var zoomsum = 0; var widthlocal = 0; var heightlocal = 0;
var group_programid = "";
var material_index = 0; var zeroindex = 0;
var prevFile = null;
var idjm = false; var programtype = 0;
var imgfile = new Array(); var imgfilegif = new Array();
//var intypeval = ['1','4','5','8','9','12','13','16'];
//电脑字体进入方式选择
var intypeval = ['1','4','5','8','9','10','11','12','13','14','15','16','17'];
$(function () {


  if (sessionStorage.getItem("upfs") != null && sessionStorage.getItem("upfs") != "") {

    if (sessionStorage.getItem("type") != "3") {
      if (sessionStorage.getItem("roleId") == "1") {
        //弹发送框，清值

        $(".confirm").click();
        $("#fsopen").click();
        sessionStorage.setItem("upfs", "");

      }
    }
  }

  console.log("分辨率" + screen.width)
  if (screen.width < 1280) {
    // console.log("小于")
    $("div:first").css("width", "120%");
  }
  if (screen.width >= 1280) {
    //  console.log("大于")
    $("div:first").css("width", "");
  }
});

//选择图片
window.loadImg = function (obj) {
  $(obj).parent().find(".upload_input").click();
  //deleteImg(obj,"1");
}
//删除,sta是判断他是否有文件，1是删页面的，else删服务器的
window.deleteImg = function (obj, sta) {
  //alert($(obj).parent().index());
  //programid节目id  model类型  FTPurl 真实路径  materialid素材id ，zeroindex 分区id
  // console.log("进来"+$(obj).parent().find("#pathimg").val())
  var imgnode = $("#imgadd .item .preview").find(("img"));
  console.log("图片个数" + imgnode.length)
  if (imgnode.length == 1) {
    swal("提示", "分区图片不能为空", "info");

    return;
  }
  if (sta == "1") {
    if ($(obj).parent().find('#materialid').val() == "" || $(obj).parent().find('#materialid').val() == "0") {
      $(obj).parent().find('input').eq(0).val('');
      $(obj).parent().find('.preview').html('');
      // $(obj).hide();  
      $(obj).parent().find('.delete').hide();
      $(obj).parent().find('#pathimg').eq(0).val('');
      $(obj).parent().find('#pathsize').eq(0).val('');
      $(obj).parent().find('#materialid').eq(0).val('0');
      imgfile[$(obj).parent().find('#hfile1').val()] = "";
      //imgfile.splice($(obj).parent().index(),1);
      //console.log(imgfile);
      // $("#program_"+selectid).find("img").eq($(obj).parent().index()).remove();
      $("#imgadd_" + $(obj).parent().find('#hfile1').val()).remove();

    } else {

      domain.ajaxUrl({
        method: 'POST',
        url: domain.testUrl + "/Threeinjection/programManagement/deleteMaterizlInfo",
        data: { "programid": sessionStorage.getItem("programid"), "devicetype": $("#devicetype").val(), "model": 1, "FTPurl": $(obj).parent().find("#pathimg").val(), "materialid": $(obj).parent().find("#materialid").val(), "zeroindex": $(obj).parent().parent().parent().parent().find("#index").val(), sessionid: sessionStorage.getItem("sid"),"fileId":$(obj).find("#fileId").val()},
        success: function (response) {

          //$(obj).parent().find('input').eq(0).val('');
          //$(obj).parent().find('.preview').html('');
          //$(obj).hide();
          $(obj).parent().find('input').eq(0).val('');
          $(obj).parent().find('.preview').html('');
          $(obj).hide();

          $(obj).parent().find('.delete').hide();
          $(obj).parent().find('#pathimg').eq(0).val('');
          $(obj).parent().find('#pathsize').eq(0).val('');
          $(obj).parent().find('#materialid').eq(0).val('0');
          imgfile[$(obj).parent().find('#hfile1').val()] = "";
          //imgfile.splice($(obj).parent().index(),1);
          //console.log(imgfile);
          // $("#program_"+selectid).find("img").eq($(obj).parent().index()).remove();

          $("#imgadd_" + $(obj).parent().find('#hfile1').val()).remove();


        }
      });
    }
    return false;
  }



  if (confirm("是否删除图片")) {
    if ($(obj).parent().find('#materialid').val() == "" || $(obj).parent().find('#materialid').val() == "0") {
      $(obj).parent().find('input').eq(0).val('');
      $(obj).parent().find('.preview').html('');
      $(obj).hide();
      $(obj).parent().find('#pathimg').eq(0).val('');
      $(obj).parent().find('#pathsize').eq(0).val(''); $(obj).parent().find('#materialid').eq(0).val('0');
      imgfile[$(obj).parent().find('#hfile1').val()] = "";


      //imgfile.splice($(obj).parent().index(),1);
      //console.log(imgfile);
      // $("#program_"+selectid).find("img").eq($(obj).parent().index()).remove();
      $("#imgadd_" + $(obj).parent().find('#hfile1').val()).remove();

    } else {



      domain.ajaxUrl({
        method: 'POST',
        url: domain.testUrl + "/Threeinjection/programManagement/deleteMaterizlInfo",
        data: { "programid": sessionStorage.getItem("programid"), "devicetype": $("#devicetype").val(), "model": 1, "FTPurl": $(obj).parent().find("#pathimg").val(), "materialid": $(obj).parent().find("#materialid").val(), "zeroindex": $(obj).parent().parent().parent().parent().find("#index").val(), sessionid: sessionStorage.getItem("sid"),"fileId":$(obj).parent().find("#fileId").val()},
        success: function (response) {

          //$(obj).parent().find('input').eq(0).val('');
          //$(obj).parent().find('.preview').html('');
          //$(obj).hide();
          $(obj).parent().find('input').eq(0).val('');
          $(obj).parent().find('.preview').html('');
          $(obj).hide();


          $(obj).parent().find('#pathimg').eq(0).val('');
          $(obj).parent().find('#pathsize').eq(0).val(''); $(obj).parent().find('#materialid').eq(0).val('0');
          imgfile[$(obj).parent().find('#hfile1').val()] = "";
          //imgfile.splice($(obj).parent().index(),1);
          //console.log(imgfile);
          // $("#program_"+selectid).find("img").eq($(obj).parent().index()).remove();

          $("#imgadd_" + $(obj).parent().find('#hfile1').val()).remove();


        }
      });
    }
  }
}
window.deleteImggif = function (obj) {
  var imgnode = $("#imgaddgif .item .preview").find(("img"));
  if (imgnode.length == 1) {
    swal("提示", "分区gif不能为空", "info");

    return;
  }
  if (confirm("是否删除动画")) {

    if ($(obj).parent().find('#materialid').val() == "" || $(obj).parent().find('#materialid').val() == "0") {
      $(obj).parent().find('#pathimggif').eq(0).val('');
      $(obj).parent().find('#pathgifsize').eq(0).val(''); $(obj).parent().find('#materialid').eq(0).val('0');

      $(obj).parent().find('input').eq(0).val('');
      $(obj).parent().find('.preview').html('');
      $(obj).hide();



      imgfilegif[$(obj).parent().find('#hfile2').val()] = "";
      //imgfile.splice($(obj).parent().index(),1);
      //console.log(imgfile);
      // $("#program_"+selectid).find("img").eq($(obj).parent().index()).remove();



      $("#imgaddgif_" + $(obj).parent().find('#hfile2').val()).remove();
    } else {
     
      domain.ajaxUrl({
        method: 'POST',
        url: domain.testUrl + "/Threeinjection/programManagement/deleteMaterizlInfo",
        data: { "programid": sessionStorage.getItem("programid"), "model": 1, "FTPurl": $(obj).parent().find("#pathimggif").val(), "materialid": $(obj).parent().find("#materialid").val(), "zeroindex": $(obj).parent().parent().parent().parent().find("#index").val(), sessionid: sessionStorage.getItem("sid"),"fileId":$(obj).parent().find("#fileId").val()},
        success: function (response) {


          $(obj).parent().find('#pathimggif').eq(0).val('');
          $(obj).parent().find('#pathgifsize').eq(0).val(''); $(obj).parent().find('#materialid').eq(0).val('0');

          $(obj).parent().find('input').eq(0).val('');
          $(obj).parent().find('.preview').html('');
          $(obj).hide();



          imgfilegif[$(obj).parent().find('#hfile2').val()] = "";
          //imgfile.splice($(obj).parent().index(),1);
          //console.log(imgfile);
          // $("#program_"+selectid).find("img").eq($(obj).parent().index()).remove();

          $("#imgaddgif_" + $(obj).parent().find('#hfile2').val()).remove();

        }
      });
    }
    // $("#program_"+selectid).find("img").eq($(obj).parent().index()).remove();
  }
}
window.preview = function (file) {
  var suffix = file.files[0].name.split('.');
  if (!/(jpg|jpeg)$/.test(suffix)) {
    swal("OMG!", "图片格式不正确，请重新输入", "error");
    return false;
  }

  var AllowImgFileSize = 5120;  //最大5M
  var imgsize = file.files[0].size / 1024;
  console.log("大小：" + imgsize)
  if (AllowImgFileSize != 0 && AllowImgFileSize < imgsize) {
    swal("OMG!", "图片大小不超过5M，请重新选择", "error");
    return false;
  }

  var file2 = file.files[0] || imgfile[$(file).parent().find("#hfile1").val()];
  if (!file2) return false;
  ///此处省略一大段逻辑///
  prevFile = file2;

  imgfile[$(file).parent().find("#hfile1").val()] = file2;

  var prevDiv = $(file).parent().find('.preview');


  //
  // alert($(file).val());
  //$(file).parent().find('.delete').hide();
  var sele = "";
  if (file.files && file.files[0]) {
    sele = "1";
    var reader = new FileReader();
    reader.onload = function (evt) {
      if ($(file).parent().find('#FTPurldele').val() != "") {
        console.log("jk" + $(file).parent().find("#FTPurldele").val())

        domain.ajaxUrl({
          method: 'POST',
          url: domain.testUrl + "/Threeinjection/programManagement/deleteMaterizlInfo",
          data: { "programid": sessionStorage.getItem("programid"), "devicetype": $("#devicetype").val(), "model": 1, "FTPurl": $(file).parent().find("#FTPurldele").val(), "materialid": $(file).parent().find("#materialid").val(), "zeroindex": $(file).parent().parent().parent().parent().find("#index").val(), sessionid: sessionStorage.getItem("sid"),"fileId":$(file).parent().find("#fileId").val()},
          success: function (response) {


            $(file).parent().find('input').eq(0).val('');
            // $(file).parent().find('.preview').html('');
            $(file).hide();


            $(file).parent().find('#pathimg').eq(0).val('');
            $(file).parent().find('#pathsize').eq(0).val('');
            $(file).parent().find('#materialid').eq(0).val('0');
            imgfile[$(file).parent().find('#hfile1').val()] = "";
            // $("#imgadd_" + $(file).parent().find('#hfile1').val()).remove();
            $(file).parent().find('#FTPurldele').val("");
          }

        });

      }
      //photoCompress
      //console.log(file.files[0]);
      var image = new Image();
      image.src = evt.target.result;
      image.onload = function () {
        var width = this.width;
        var height = this.height;
        var width1 = $("#from_" + selectid).find("#width").val();
        var height1 = $("#from_" + selectid).find("#high").val();
        if (parseInt(height) > parseInt(height1) || parseInt(width) > parseInt(width1)) {
          //隐藏
          swal("OMG!", "选择动画图片不能超过分区宽高,图片尺寸为：" + width + "*" + height, "error");
          $(file).parent().find('.delete').hide();
          $(file).val("");
          return;

        }
        $("#program_" + selectid).find("#imgadd_" + $(file).parent().find("#hfile1").val()).remove();

        $("#program_" + selectid).append("<img  id=imgadd_" + $(file).parent().find("#hfile1").val() + " src='" + evt.target.result + "'  class='img-rounded' style=height:" + 100 + "%;width:" + parseInt(100) + "%;>");
        prevDiv.html('<img src="' + evt.target.result + '" />');
        alert("ss"+$("#imgadd_" + $(file).parent().find("#hfile1").val()))
        canvasDataURL(evt.target.result, this.width, $("#imgadd_" + $(file).parent().find("#hfile1").val()))
        //alert(width+'======'+height+"=====");     
      };
    }


    //  console.log("就好"+ file.files[0].size);



    reader.readAsDataURL(file.files[0]);
    $.fn.jqLoading({ height: 100, width: 240, text: "图片上传中，请耐心等待...." });
    var formData = new FormData();
    formData.append('file', file.files[0]);
    $.ajax({
      url: domain.testUrl + "/Threeinjection/programManagement/FTPupload?coId=" + sessionStorage.getItem("coid"),
      type: 'POST',
      cache: false,
      data: formData,
      processData: false,
      contentType: false
    }).done(function (res) {
      $.fn.jqLoading("destroy");
      // logo=res;
      //res=logo;
      //pathimggif
      res = JSON.parse(res);
      $(file).parent().find("#pathimg").val(res.data);
      console.log("imgsize:" + imgsize);

      $(file).parent().find("#pathsize").val(parseInt(imgsize));


      $(file).parent().find("#materialid").val(0);



      // $(file).parent().find("#materialid").val();
      // console.log("就很好 j"+$(file).parent().find("#materialid").val(0));
      try {
        $(file).parent().find("#fileId").val(res.fileId);
        console.log("就好" + res.fileId + "," + $(file).parent().find("#fileId").val())
      } catch (ex) {

      }

    }).fail(function (res) {
    });
  } else {//IE
    //prevDiv.html('<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>');
  }
  $(file).parent().find('.delete').show();
}
window.previewgif = function (file) {
  var suffix = file.files[0].name.split('.');
  if (!/(gif)$/.test(suffix)) {
    swal("OMG!", "gif格式不正确，请重新输入", "error");
    return false;
  }

  var AllowImgFileSize = 5120;  //最大5M
  var gifsize = file.files[0].size / 1024;
  console.log("大小：" + gifsize)
  if (AllowImgFileSize != 0 && AllowImgFileSize < gifsize) {
    swal("OMG!", "gif大小不超过5M，请重新选择", "error");
    return false;
  }

  var file2 = file.files[0] || imgfilegif[$(file).parent().find("#hfile2").val()];
  if (!file2) return false;
  ///此处省略一大段逻辑///
  prevFile = file2;

  imgfilegif[$(file).parent().find("#hfile2").val()] = file2;

  var prevDiv = $(file).parent().find('.preview');


  //
  // alert($(file).val());
  //$(file).parent().find('.delete').hide();
  var sele = "";
  if (file.files && file.files[0]) {
    sele = "1";
    var reader = new FileReader();
  
    var fr = new FileReader();
    //console.log(fr);
    fr.onloadend = function(e) {

      playGIF.doParse(new Stream(e.target.result),function(hdr,frames,canvas){
        //console.log(hdr);
        //console.log(frames.length);
        //帧
        var s = 0;
        for(var i=0;i<frames.length;i++){
          s += frames[i].delay;
        }
        //时长
       
        $(file).parent().find("#giftime").val((s * 10));
       // console.log('total time:' + (s * 10) + " milliseconds");
    });}
    fr.readAsBinaryString(file.files[0]);

    reader.onload = function (evt) {
      if ($(file).parent().find('#FTPurlgif').val() != "") {


        domain.ajaxUrl({
          method: 'POST',
          url: domain.testUrl + "/Threeinjection/programManagement/deleteMaterizlInfo",
          data: { "programid": sessionStorage.getItem("programid"), "devicetype": $("#devicetype").val(), "model": 1, "FTPurl": $(file).parent().find("#FTPurlgif").val(), "materialid": $(file).parent().find("#materialid").val(), "zeroindex": $(file).parent().parent().parent().parent().find("#index").val(), sessionid: sessionStorage.getItem("sid"),"fileId":$(file).parent().find("#fileId").val()},
          success: function (response) {


            $(file).parent().find('input').eq(0).val('');
            // $(file).parent().find('.preview').html('');
            $(file).hide();


            $(file).parent().find('#pathimg').eq(0).val('');
            $(file).parent().find('#pathsize').eq(0).val('');
            $(file).parent().find('#materialid').eq(0).val('0');
            imgfile[$(file).parent().find('#hfile1').val()] = "";
            // $("#imgadd_" + $(file).parent().find('#hfile1').val()).remove();
            $(file).parent().find('#FTPurlgif').val("");
          }

        });

      }

      var image = new Image();
      image.src = evt.target.result;
      image.onload = function () {
        var width = image.width;
        var height = image.height;
        var width1 = $("#from_" + selectid).find("#width").val();
        var height1 = $("#from_" + selectid).find("#high").val();
        
        $("#gifwidepth").val(width+"*"+height);
        if (parseInt(height) > parseInt(height1) || parseInt(width) > parseInt(width1)) {
          
          swal("OMG!", "选择动画图片不能超过分区宽高,动画尺寸为：" + width + "*" + height, "error");
          $(file).val("");
          return;

        }
        prevDiv.html('<img src="' + evt.target.result + '" />');
        
        $("#program_" + selectid).find("#imgaddgif_" + $(file).parent().find("#hfile2").val()).remove();
        
        $("#program_" + selectid).append("<img  id=imgaddgif_" + $(file).parent().find("#hfile2").val() + " src='" + evt.target.result + "'  class='img-rounded' style=height:" + width + "%;width:" + height + "%;>");
        //gif尺寸小于分区
        gifwg(selectid);
        var formData = new FormData();
        formData.append('file', file.files[0]);
        $.fn.jqLoading({ height: 100, width: 240, text: "gif上传中，请耐心等待...." });
        $.ajax({
          url: domain.testUrl + "/Threeinjection/programManagement/FTPupload?coId=" + sessionStorage.getItem("coid"),
          type: 'POST',
          cache: false,
          data: formData,
          processData: false,
          contentType: false
        }).done(function (res) {
          $.fn.jqLoading("destroy");
          // logo=res;
          //res=logo;
          //pathimggif
          res = JSON.parse(res);
          $(file).parent().find("#pathimggif").val(res.data);
          //file前面被清了，在这里面来算大小会报错，size会报错，所以用了全局的
          $(file).parent().find("#pathgifsize").val(parseInt(gifsize));

          // if($(file).parent().find("#pathimggif").val()!=""||$(file).parent().find("#pathimggif").val()!=null){
          //   deleteImggif(file);
          // }
          $(file).parent().find("#materialid").val(0);

          //console.log(res);
          try {
            $(file).parent().find("#fileId").val(res.fileId);
          } catch (ex) {

          }
        }).fail(function (res) {
        });
        $(file).parent().find('.delete').show();
      }
    }
    reader.readAsDataURL(file.files[0]);
  } else {//IE
    //prevDiv.html('<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>');
  }

}

//删除分区
window.del = function (thi) {
  if (confirm("是否删除分区")) {
    //alert( $("#from_"+$(thi).parent().parent().attr("id")).parent().html());
    //zeroindex分区号，model   ，FTPurl 文件url，materialid
    console.log("就看见" + $("#from_" + $(thi).parent().parent().attr("id")).find("#index").val())
    if ($("#from_" + $(thi).parent().parent().attr("id")).find("#index").val() != "") {
      domain.ajaxUrl({
        method: 'POST',
        url: domain.testUrl + "/Threeinjection/programManagement/delprogramAllInfo",
        data: { "model": 1, "programid": sessionStorage.getItem("programid"), zeroindex: $("#from_" + $(thi).parent().parent().attr("id")).find("#index").val(), FTPurl: $("#from_" + $(thi).parent().parent().attr("id")).find("#FTPurl").val(), materialid: $("#from_" + $(thi).parent().parent().attr("id")).find("#materialid").val(), sessionid: sessionStorage.getItem("sid") },
        success: function (response) {
          response = JSON.parse(response);
          // console.log(response);
          if (response.code == "200") {
            if (zeroindex >= 0) {
              zeroindex = zeroindex - 1;
            }
            $(thi).parent().parent().remove();
            $("#from_" + $(thi).parent().parent().attr("id")).parent().remove();
            $("#program_" + $(thi).parent().parent().attr("id")).remove();
            if ($("#program").find("div").length == 0) {
              $(".panel-heading").click();
              // $("#splitscreen").css("height",420);

            } else {

              $("#material li").click();
            }

          }
          parent.window.frames["iftab_15"].window.cxlist();
          

        }
      });
    } else {
      $(thi).parent().parent().remove();
      $("#from_" + $(thi).parent().parent().attr("id")).parent().remove();

      $("#program_" + $(thi).parent().parent().attr("id")).remove();

      if ($("#program").find("div").length == 0) {

        $(".panel-heading").click();
        // $("#splitscreen").css("height",420);

      } else {

        $("#material li").click();
      }

    }
  }
};

function canvas() {


  var c = document.getElementById("screen_size");

  var ctx = c.getContext("2d");
  ctx.canvas.width = ctx.canvas.width;
  var width = $("#program")[0].offsetWidth;
  var height = $("#program")[0].offsetHeight;

  // if(width>698 || height> 180) {
  //   $("#screen_size").attr("width",1).attr("height",1);
  // return;
  // }
  $("#screen_size").css({ "left": $("#program")[0].offsetLeft, "top": $("#program")[0].offsetTop });
  $("#screen_size").attr("width", width + 20).attr("height", height + 20);

  //if(width>60) {
  ctx.moveTo(1, height + 5);
  ctx.lineTo(1, height + 15);
  ctx.moveTo(1, height + 10);
  ctx.lineTo(width / 2 - 20, height + 10);
  ctx.moveTo(width / 2 + 20, height + 10);
  ctx.lineTo(width, height + 10);
  ctx.moveTo(width, height + 5);
  ctx.lineTo(width, height + 15);
  // }

  //if(height>60) {
  ctx.moveTo(width + 5, 1);
  ctx.lineTo(width + 15, 1);
  ctx.moveTo(width + 10, 1);
  ctx.lineTo(width + 10, height / 2 - 10);
  ctx.moveTo(width + 10, height / 2 + 10);
  ctx.lineTo(width + 10, height);
  ctx.moveTo(width + 5, height);
  ctx.lineTo(width + 15, height);
  //}

  ctx.strokeStyle = "red";
  ctx.stroke();
  var sw = sessionStorage.getItem("width");
  var sh = sessionStorage.getItem("high");
  ctx.fillStyle = 'rgba(255,0,0,1)';
  ctx.font = "13px arial";
  //  if(width>60) {
  ctx.fillText(sw, width / 2 - sw.length * 3, height + 14);
  ctx.save();
  // }
  //if(height>60) {
  ctx.rotate(-Math.PI / 2);
  ctx.fillText(sh, -height / 2 - sh.length * 3, width + 14);
  //  }
  ctx.restore();
}

var selectid = "";//选择的分区

$(function () {
  group_programid = sessionStorage.getItem("group_programid");

  $("#programid").val(sessionStorage.getItem("group_programid"));

  //单双色只有文本
  $("#devicetype").val(sessionStorage.getItem("type"));
  if ($("#devicetype").val() == "0" || $("#devicetype").val() == "1") {
    $("#materialinfo li:eq(1),#materialinfo li:eq(2)").hide()
    $("#Dazzle,#typefaceval").parent().hide();
  } else {
    $("#materialinfo li:eq(1),#materialinfo li:eq(2)").show();
    $("#Dazzle").parent().show();
  }
  if (sessionStorage.getItem("roleId") == "3") {
    $("#addfq").hide();
    $("#zoom").css("position", "");
  }

  //节目播放次数
  for (var i = 1; i <= 23; i++) {

      $("#playtime").append("<option value='" + i + "' selected>" + i + "</option>");
   
  }

//把时段时间设为00
for (var i = 1; i <= 8; i++) {

  showTimer('liveStart' + i, 1);
  showTimer('liveEnd' + i, 1);
  $('#liveStart' + i).find("input:eq(0)").val("00");
  $('#liveStart' + i).find("input:eq(2)").val("00");
  $('#liveEnd' + i).find("input:eq(0)").val("00");
  $('#liveEnd' + i).find("input:eq(2)").val("00");
}



//时段默认显示一个值
setTimeout(function () {
  timeChange();
}, 1000);

$("#highTime").click(function(){
  console.log("好几款"+$("#highTime").parent().next().html())
  if($(this).is(":checked")){
    $("#highTime").parent().next().show();
    $("#highTime").parent().next().css("display","webkit-inline-box");
      $("#liveCount").parent().show();
      $("#liveTime").parent().show();
  }else{
    $("#highTime").parent().next().hide();

    $("#liveCount").parent().hide();
    $("#liveTime").parent().hide();
    console.log("隐藏")
  }
});


  //语音

  $("#isplayvoice").change(function () {
    if ($(this).val() == "1") {
      swal("温馨提示", "播放语音已开启，“节目名称”为播放的内容", "info");
    }
  });
  //播放类型
  $("#playtype").change(function () {
    if ($(this).val() == "0") {

      $("#playtime").prev().text("次数");
    } else {
      $("#playtime").prev().text("时间（s)");
    }
  });

  // console.log("你"+$("#devicetype").val())

  $("#materialinfo li a").click(function () {
    if ($(this).text() == " 动画") {
      var gifsize = $("img[src='static/img/sp.png']").length - 1;
      if (gifsize > 0) {
        swal("提示", " 节目只支持1个动画分区显示", "info");
        return false;
      }
    }
    //alert();
    if ($(".transparent_class").length == 3) {

      swal("提示", "节目分区最多可以添加3个", "info");
      return false;
    }


    partitioncz(this);

  });
  
 
  $("#zoom img").eq(0).click(function () {
    var width = Math.round($("#program").outerWidth()) * 2;
    var height = Math.round($("#program").outerHeight()) * 2;
    //转四舍五入，转int的话，值可能会有问题，会少
    if (height > 192 || zoomsum == 2) {

      return false;
    }

    widthlocal = width;
    heightlocal = height;
    $("#zoom img").eq(1).show();
    zoomsum++;
    $("#zoomsum").text(zoomsum);
    $("#program").css("width", width);
    $("#program").css("height", height);
    //遍历所有分区
    var Recordselect=selectid;
    
  
    $(".transparent_class").each(function (i) {
      $(".transparent_class").eq(i).css("width", parseInt($(".transparent_class").eq(i).css("width")) * 2);
      $(".transparent_class").eq(i).css("height", parseInt($(".transparent_class").eq(i).css("height")) * 2);

      //x和y轴移动
      if (parseInt($(".transparent_class").eq(i).css("left")) > 0) {
        //var left=parseInt(width)-parseInt($(".transparent_class").eq(i).css("width"));
        var left = parseInt($(".transparent_class").eq(i).css("left")) * 2;
        $(".transparent_class").eq(i).css("left", left);
      }
      if (parseInt($(".transparent_class").eq(i).css("top")) > 0) {
        //var left=parseInt(width)-parseInt($(".transparent_class").eq(i).css("width"));
        var top = parseInt($(".transparent_class").eq(i).css("top")) * 2;
        $(".transparent_class").eq(i).css("top", top);
      }

      var id = $(this).attr("id").split("_")[1]
      var reg = new RegExp("px", "g");
      var size = $('#from_' + id).find("#fontsizeadd").find("option:selected").text().replace(reg, "");
      size = size.split("*")[0];
      $("#program_" + id).css("font-size", size + "px");
      if (zoomsum > 0) {
        var zoomsumval = zoomsum * 2;
        zoomsumval = size * zoomsumval;
        $("#program_" + id).css("font-size", zoomsumval + "px");
      }
      //gif尺寸小于分区
      gifwg(id);
       //画布
       selectid=id;
      textcanvas(id);
      
    
    });
  
    //字体放大



    canvas();
    Recordselect=selectid;
    // alert(123);
  });
  $("#zoom img").eq(1).click(function () {

    var width = parseInt($("#program").css("width")) / 2;
    var height = parseInt($("#program").css("height")) / 2;
    if (zoomsum > 0) {
      zoomsum--;
      $("#zoomsum").text(zoomsum);
      if (zoomsum == 0) {

        $("#zoom img").eq(1).hide();
      }
    }
    if (height < 16) {

      return;
    }

    widthlocal = width;
    heightlocal = height;
    $("#program").css("width", width);
    $("#program").css("height", height);
    var Recordselect=selectid;
    //遍历所有分区
    $(".transparent_class").each(function (i) {

      $(".transparent_class").eq(i).css("width", parseInt($(".transparent_class").eq(i).css("width")) / 2);
      $(".transparent_class").eq(i).css("height", parseInt($(".transparent_class").eq(i).css("height")) / 2);
      //x和y轴移动
      if (parseInt($(".transparent_class").eq(i).css("left")) > 0) {
        //var left=parseInt(width)-parseInt($(".transparent_class").eq(i).css("width"));
        var left = parseInt($(".transparent_class").eq(i).css("left")) / 2;


        $(".transparent_class").eq(i).css("left", left);
      }

      if (parseInt($(".transparent_class").eq(i).css("top")) > 0) {
        //var left=parseInt(width)-parseInt($(".transparent_class").eq(i).css("width"));
        var top = parseInt($(".transparent_class").eq(i).css("top")) / 2;
        $(".transparent_class").eq(i).css("top", top);
      }
      var id = $(this).attr("id").split("_")[1]
      var reg = new RegExp("px", "g");
      var size = $('#from_' + id).find("#fontsizeadd").find("option:selected").text().replace(reg, "");
      size = size.split("*")[0];
      $("#program_" + id).css("font-size", size + "px");
      if (zoomsum > 0) {
        var zoomsumval = zoomsum * 2; zoomsumval = size * zoomsumval;
        $("#program_" + id).css("font-size", zoomsumval + "px");
      }
      //gif尺寸小于分区
      gifwg(id);
       //画布
       selectid=id;
    textcanvas(id);
    });
    canvas(); 
    Recordselect=selectid;
  });
  
  $.ajax({
    type: "POST",
    //url: "上传图片接口",
    url: domain.testUrl + "/Threeinjection/programManagement/queryprogramAllInfo",
    data: { "programid": sessionStorage.getItem("programid"), sessionid: sessionStorage.getItem("sid") },
    //视情况将base64的前面字符串data:image/png;base64,删除
    async: true,
    success: function (response) {
      canvas();
      // response={"programInfo":[{"programid":"1299","order_id":"1","group_programid":"5","type":"0","starttime":"Sun Jan 01 00:00:00 CST 2012","endtime":"Wed Dec 30 00:00:00 CST 2099","playtime":"1","playtype":"0","devicetype":"2","festivalname":"节目_文本","isplayvoice":"0","protimeinfo":[{"programid":"1299","starthour":"00:00","endhour":"23:59","timeid":"1299"}],"children":[{"zeroindex":"1","type":"0","lef":"0","top":"0","width":"256","high":"64","children":[{"materialid":"1591","material_index":"1","text":"黑恶必除，↵ 除恶务尽","FTPurl":"/application/lgsvftp/lgsvfullcolor/group153/5_1_1.bin","advancedid":"0","size":"46","type":"0","intype":"32","inspeed":"1","fontcolor":"0","fontsize":"3","backcolor":"0","staytime":"4","fonteffect":"0","model":"1"}]}]}]};
      // response=response.reg
    
      // console.log("jhjjjkhjk"+JSON.stringify(response));
      var obj = eval("(" + response + ")");
      var reg = new RegExp(/\n/g, "g");
      obj.programInfo = obj.programInfo.replace(reg, "↵");
      response = JSON.parse(obj.programInfo);
    
      var materialid = response;
      group_programid = response[0].group_programid;
      $("#order").val(response[0].order_id);
      $("#festivalname").val(response[0].festivalname);
      $("#devicetype").val(response[0].devicetype);
      $("#typejm").val(response[0].type);
      $("#playtype").val(response[0].playtype);
      $("#isplayvoice").val(response[0].isplayvoice);
      // alert(response[0].playtime);
      $("#playtime").val(response[0].playtime);
      if ($("#playtype").val() == "0") {

        $("#playtime").prev().text("次数");
      } else {
        $("#playtime").prev().text("时长(s)");
      }

      //转换开始日期时间
      var d = new Date(parseInt(response[0].starttime));
      d = d.Format("yyyy-MM-dd hh:mm:ss");

      $("#starttime").val(d.substring(0, 10));

     // $("#timeid").val(d.substring(10));

      var d1 = new Date(parseInt(response[0].endtime));
      d1 = d1.Format("yyyy-MM-dd hh:mm:ss");
      
      $("#endtime").val(d1.substring(0, 10));

//周期
      var checkArry = response[0].days;
      console.log("斤斤计较"+response[0].protimeinfo.length)
      if(response[0].protimeinfo.length>0){
        $("#highTime").click();
      
      var checkArry=response[0].days.toString();
      checkArry=checkArry.substring(1,checkArry.length-1);
      var splitCheck=checkArry.split(',');
      
      $(".select dd ul li input").click();
          for(var k=0;k<splitCheck.length;k++){

            $(".select dd ul li:eq("+(splitCheck[k]-1)+") input").click();
         }
        

      $("#liveCount").val(response[0].protimeinfo.length);
      timeChange();
      //时间段
      for(var j=0;j<response[0].protimeinfo.length;j++){
       // console.log("time:"+response[0].protimeinfo[j].starthour+"-"+response[0].protimeinfo[j].endhour);
       $("#liveStart"+(j+1)).attr("liveId",response[0].protimeinfo[j].id);
          for(var jj=0;jj<2;jj++){
       var hour=((jj+1)%2)==0?response[0].protimeinfo[j].endhour.split(':'):response[0].protimeinfo[j].starthour.split(':');
       var thisid=((jj+1)%2)==0?"#liveEnd":"#liveStart";

       $(thisid+(j+1)+" input:eq(0)").val(hour[0]);
       $(thisid+(j+1)+" input:eq(2)").val(hour[1]);
      
          }
      }
      }
//分区类型
var typeValue=0;
if(response[0].children!= undefined){
      try {
       
        for (var i = 0; i < response[0].children.length; i++) {
       if(response[0].children[i].type==4||response[0].children[i].type==5){
        $("#materialinfo li").eq(parseInt(response[0].children[i].type)-1).find("a").click();   
       }else{
         $("#materialinfo li").eq(response[0].children[i].type).find("a").click();   

       }
         
          var ii = parseInt(i) + 1;
       
         
          //	   $("#materialinfo li a")
          //alert(response[0].children[i].type);
          //文字
          typeValue=response[0].children[i].type;
          
          $("#from_" + selectid).find("#index").val(ii);
          if (response[0].children[i].type==0) {

            $("#program_" + selectid).css("width", response[0].children[i].width + "px");
            $("#program_" + selectid).css("height", response[0].children[i].high + "px");

            $("#program_" + selectid).css("top", response[0].children[i].top + "px");
            $("#program_" + selectid).css("left", response[0].children[i].lef + "px");
            //alert(response[0].children[i].children[0].text);
            var regtext = new RegExp(/\↵/g, "g");  //全文匹配
            var text = response[0].children[i].children[0].text.toString().replace(regtext, "\n");

            $("#program_" + selectid).append(text);
            console.log("好几款还是" + text);
            //  $("#program_" + selectid).find("Dazzle").val("0");


            //$("#program_"+selectid).css("overflow","hidden").css("white-space","pre");
            //chen，预览
            $("#program_" + selectid).css("word-wrap", "break-word").css("word-break", "break-all");
            //$("#program_"+selectid).css("left",response[0].children[i].lef+"px");

        
            $("#program_" + selectid).css("color", fontcolorval(response[0].children[i].children[0].fontcolor));


            $("#from_" + selectid).find("#left").val(response[0].children[i].lef);

            $("#from_" + selectid).find("#top").val(response[0].children[i].top);

            $("#from_" + selectid).find("#width").val(response[0].children[i].width);

            $("#from_" + selectid).find("#high").val(response[0].children[i].high);
            if (response[0].children[i].children[0].advancedid == "3") {
            var alignment,alignmenttext;

            alignment=response[0].children[i].children[0].fontalign=="0"?"left":"center";
            alignmenttext=response[0].children[i].children[0].fontalign=="0"?"左对齐":"居中";
            $("#from_" + selectid).find(".alignmenttext").html("<span val='"+alignment+"'>"+alignmenttext+ "</span>"); 
            }

            $("#from_" + selectid).find("#intype").val(response[0].children[i].children[0].intype);

            $("#from_" + selectid).find("#inspeed").val(response[0].children[i].children[0].inspeed);
          
            $("#from_" + selectid).find("#fontcolor").val(fontcolorval(response[0].children[i].children[0].fontcolor));
            
            // alert(response[0].children[i].children[0].fontsize);
            $("#from_" + selectid).find("#fontsizeadd").val(response[0].children[i].children[0].fontsize);
            //fontname
            //alert(response[0].children[i].children[0].fontsize);
            // $("#from_" + selectid).find("#typefaceval").val($("#from_" + selectid).find("#" + response[0].children[i].children[0].fontname).val());
            //chen改
            //$("#program_" + selectid).html("<div  style='width:inherit;font-family:monospace'>" + text + "</div>" + "<input type='hidden' id='imgDataURL'><input type='hidden' id='leftdw' value=" + $("#program_" + selectid).find("#leftdw").val() + ">");
            $("#program_" + selectid).css("line-height", "1");
            console.log($("#from_" + selectid).find("#fontsizeadd").find("option:selected").text());
            var fontsize = $("#from_" + selectid).find("#fontsizeadd").find("option:selected").text().split("*");

            $("#program_" + selectid).css("font-size", fontsize[1] + "px");

            $("#from_" + selectid).find("#backcolor").val(fontcolorvaltow(response[0].children[i].children[0].backcolor));

            // alert(response[0].children[i].children[0].backcolor);

            //alert(response[0].children[i].children[0].fontsize);

            $("#from_" + selectid).find("#staytime").val(response[0].children[i].children[0].staytime);

            //alert(response[0].children[i].children[0].type);

            $("#from_" + selectid).find("#type").val(response[0].children[i].children[0].type);

            $("#from_" + selectid).find("#FTPurl").val(response[0].children[i].children[0].FTPurl);
            $("#from_" + selectid).find("#size").val(response[0].children[i].children[0].size);
            $("#from_" + selectid).find("#materialid").val(response[0].children[i].children[0].materialid);

            if (response[0].children[i].children[0].txtpath == null || response[0].children[i].children[0].txtpath == "null") {
              $("#from_" + selectid).find("#txtpath").val("");
            } else {
              $("#from_" + selectid).find("#txtpath").val(response[0].children[i].children[0].txtpath);
            }
            // $("#from_"+selectid).find("#Dazzle,#randomFontColor").parent().show();
            $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", "");
            console.log("advancedid值" + response[0].children[i].children[0].advancedid);
           
            //电脑字体
        
            if (response[0].children[i].children[0].advancedid == "1") {
              // $("#from_" + selectid).find("#alignment").parent().show();
              // $("#from_" + selectid).find("#typefaceval").parent().css("margin-left", "-24.5%");
              $("#from_" + selectid).find("#alignment").parent().show();
              // $("#from_"+selectid).find("#typefaceval").parent().css("margin-left","-50%");
              $("#from_" + selectid).find("#texttype").val("1");

              $("#from_" + selectid).find("#typefaceval").val($("#from_" + selectid).find("#typefaceval").find("#" + response[0].children[i].children[0].fontname).val());
              $("#from_" + selectid).find("#randomFontColor").val(response[0].children[i].children[0].randomFontColor);
              $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", "-24.8%");

            }
            //word 电脑字体
            // alert(response[0].children[i].children[0].advancedid);
            if (response[0].children[i].children[0].advancedid == "3") {
              // $("#from_"+selectid).find("#alignment").parent().show();
              //$("#from_"+selectid).find("#fontcolordiv,#fontsizediv,#fosizeval").hide();
//               $("#from_" + selectid).find("#alignment").parent().hide();
//               $("#from_" + selectid).find("#typefaceval").parent().hide();
//               $("#from_" + selectid).find("#randomFontColor").parent().hide();
//               $("#from_" + selectid).find("#Dazzle").parent().hide();
//               $("#from_" + selectid).find("#fontsizeadd").parent().hide();
//               $("#from_" + selectid).find("#texttype").val("1");
//               $("#from_" + selectid).find("#text_pic_form").show();
             
//               $("#from_" + selectid).find("#text_pic_form").find(".text-size button:eq(0)").text(response[0].children[i].children[0].fontsize);
// console.log("sizefdddd"+response[0].children[i].children[0].fontsize)
//              // response[0].children[i].children[0].fontsize
              
//              init();
//              Canvasfont();
              //();
               // $("#from_"+selectid).find("#alignment").parent().show();
              //$("#from_"+selectid).find("#fontcolordiv,#fontsizediv,#fosizeval").hide();
              $("#from_" + selectid).find("#alignment").parent().hide();
              $("#from_" + selectid).find("#typefaceval").parent().hide();
              $("#from_" + selectid).find("#randomFontColor").parent().hide();
              $("#from_" + selectid).find("#Dazzle").parent().hide();
              $("#from_" + selectid).find("#fontsizeadd").parent().hide();
              $("#from_" + selectid).find("#texttype").val("1");
              $("#from_" + selectid).find("#text_pic_form").show();
              $("#from_" + selectid).find("#day,#week,#hour").hide();
              $("#from_" + selectid).find(".daytext,.weektext,.hourtext").parent().hide();
              $("#from_" + selectid).find(".timetext").parent().hide();
              $("#from_" + selectid).find("#text_pic_form").find(".text-size button:eq(0)").text(response[0].children[i].children[0].fontsize);
console.log("sizefdddd"+response[0].children[i].children[0].fontsize)
             // response[0].children[i].children[0].fontsize
              
             init();
             Canvasfont();
            }
            //炫彩效果
            if (response[0].children[i].children[0].advancedid == "2") {
              $("#from_" + selectid).find("#typefaceval").parent().hide();
              $("#from_" + selectid).find("#Dazzle").html("<option value='" + response[0].children[i].children[0].fonteffect + "'>炫彩效果" + response[0].children[i].children[0].fonteffect + "</option>");
              $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", "");
              $("#from_" + selectid).find("#randomFontColor").parent().hide();
            }
            //炫彩字体
            if (response[0].children[i].children[0].advancedid == "4") {
              console.log("隐藏颜色了")
              $("#from_" + selectid).find("#alignment").parent().hide();
              $("#from_" + selectid).find("#typefaceval").val(response[0].children[i].children[0].advancedid);
              $("#from_" + selectid).find("#Dazzle").parent().show();
              $("#from_" + selectid).find("#fontcolor").parent().hide();
              $("#from_" + selectid).find("#Dazzle").html("<option value='" + response[0].children[i].children[0].fonteffect + "'>炫彩效果" + response[0].children[i].children[0].fonteffect + "</option>");
              $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", "");
            }
            
            //字体特效
            if (response[0].children[i].children[0].randomFontColor != "0") {
              $("#from_" + selectid).find("#randomFontColor").val(response[0].children[i].children[0].randomFontColor);

              $("#from_" + selectid).find("#Dazzle").parent().hide();
              $("#from_" + selectid).find("#randomFontColor").parent().css("margin-left", "-24.8%");
            }


            if (response[0].children[i].children[0].fontcolor == "2" || response[0].children[i].children[0].fontcolor == "6") {

              $('#from_' + selectid).find("textarea").css("color", "black");
            } else {
              // console.log("没进来"+response[0].children[i].children[0].fontcolor)
              $('#from_' + selectid).find("textarea").css("color", $('#from_' + selectid).find("#fontcolor").val());
            }

            // $("#from_" + selectid).find("#texttype").val(response[0].children[i].children[0].advancedid);
            $("#from_" + selectid).find("#txt").val(response[0].children[i].children[0].text);


            // var text = response[0].children[i].children[0].text.toString().replace("↵", "\n")
            $("#from_" + selectid).find("#fosizeval").val(text);
            console.log("文本" + $("#from_" + selectid).find("#fosizeval").val())

            $("#from_" + selectid).find("#alignment").val(response[0].children[i].children[0].fontalign);
            if ($("#from_" + selectid).find("#alignment").val() == "0") {

              $("#program_" + selectid).css("display", "");
              $("#program_" + selectid).css("align-items", "");
            }
            if ($("#from_" + selectid).find("#alignment").val() == "2") {
              $("#program_" + selectid).css("display", "grid");
              $("#program_" + selectid).css("align-items", "flex-end");
            }
            if ($("#from_" + selectid).find("#alignment").val() == "1") {

              $("#program_" + selectid).css("display", "grid");
              $("#program_" + selectid).css("align-items", "center");

            }

            $("#program_" + selectid).css("white-space", "pre-wrap");
           textcanvas(selectid);
          }

          // console.log(response);
          //图片
          if (response[0].children[i].type == 1) {
            //partitioncz();
            $("#program_" + selectid).css("white-space", " ");
            picture(response, i); $("#from_" + selectid).find("#texttype").parent().hide();
          }
          //动画
          if (response[0].children[i].type == 2) {
            $("#program_" + selectid).css("white-space", " ");
            //partitioncz();
            new ZResize({
              stage: "#program", //舞台 
              item: '#program_' + selectid, //可缩放的类名 
            });
            $(".resize-panel").css("z-index",1000);
            picturegif(response, i);; $("#from_" + selectid).find("#texttype").parent().hide();
          } 
       
          //时间
          if (response[0].children[i].type==4) {
           
            $("#program_" + selectid).css("width", response[0].children[i].width + "px");
            $("#program_" + selectid).css("height", response[0].children[i].high + "px");

            $("#program_" + selectid).css("top", response[0].children[i].top + "px");
            $("#program_" + selectid).css("left", response[0].children[i].lef + "px");
            
            //alert(response[0].children[i].children[0].text);
            var regtext = new RegExp(/\↵/g, "g");  //全文匹配
            var text = response[0].children[i].children[0].text.toString().replace(regtext, "\n");

          //  $("#program_" + selectid).append(text);
           
           
            //chen，预览
            $("#program_" + selectid).css("word-wrap", "break-word").css("word-break", "break-all");
        
            $("#program_" + selectid).css("color", fontcolorval(response[0].children[i].children[0].fontcolor));


            $("#from_" + selectid).find("#left").val(response[0].children[i].lef);

            $("#from_" + selectid).find("#top").val(response[0].children[i].top);

            $("#from_" + selectid).find("#width").val(response[0].children[i].width);

            $("#from_" + selectid).find("#high").val(response[0].children[i].high);
           

            $("#from_" + selectid).find("#intype").val(response[0].children[i].children[0].intype);

            $("#from_" + selectid).find("#inspeed").val(response[0].children[i].children[0].inspeed);
          
            $("#from_" + selectid).find("#fontcolor").val(fontcolorval(response[0].children[i].children[0].fontcolor));
            
            // alert(response[0].children[i].children[0].fontsize);
            $("#from_" + selectid).find("#fontsizeadd").val(response[0].children[i].children[0].fontsize);
           
            $("#program_" + selectid).css("line-height", "1");
            console.log($("#from_" + selectid).find("#fontsizeadd").find("option:selected").text());
            var fontsize = $("#from_" + selectid).find("#fontsizeadd").find("option:selected").text().split("*");

            $("#program_" + selectid).css("font-size", fontsize[1] + "px");

            $("#from_" + selectid).find("#backcolor").val(fontcolorvaltow(response[0].children[i].children[0].backcolor));

            // alert(response[0].children[i].children[0].backcolor);

            //alert(response[0].children[i].children[0].fontsize);

            $("#from_" + selectid).find("#staytime").val(response[0].children[i].children[0].staytime);

           
            $("#from_" + selectid).find("#type").val(parseInt(response[0].children[i].type)-1);

            $("#from_" + selectid).find("#FTPurl").val(response[0].children[i].children[0].FTPurl);
            $("#from_" + selectid).find("#size").val(response[0].children[i].children[0].size);
            $("#from_" + selectid).find("#materialid").val(response[0].children[i].children[0].materialid);

            if (response[0].children[i].children[0].txtpath == null || response[0].children[i].children[0].txtpath == "null") {
              $("#from_" + selectid).find("#txtpath").val("");
            } else {
              $("#from_" + selectid).find("#txtpath").val(response[0].children[i].children[0].txtpath);
             
            }
            // $("#from_"+selectid).find("#Dazzle,#randomFontColor").parent().show();
            $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", "");
            console.log("advancedid值" + response[0].children[i].children[0].advancedid);
           
          
            //word 电脑字体
            $("#from_" + selectid).find("#texttype").parent().hide();
            if (response[0].children[i].children[0].advancedid == "5") {
              // $("#from_"+selectid).find("#alignment").parent().show();
              //$("#from_"+selectid).find("#fontcolordiv,#fontsizediv,#fosizeval").hide();
              $("#from_" + selectid).find("#alignment").parent().hide();
              $("#from_" + selectid).find("#typefaceval").parent().hide();
              $("#from_" + selectid).find("#randomFontColor").parent().hide();
              $("#from_" + selectid).find("#Dazzle").parent().hide();
              $("#from_" + selectid).find("#fontsizeadd").parent().hide();
              $("#from_" + selectid).find("#texttype").val("1");
              $("#from_" + selectid).find("#text_pic_form").show();
              //字体大小值
              var fontsize=response[0].children[i].children[0].fontsize;
              if(fontsize=="1"){
                fontsize=16;
              }else if(fontsize=="2"){
                fontsize=24;
              }
              else if(fontsize=="3"){
                fontsize=32;
              }
              else if(fontsize=="4"){
                fontsize=12;
              }
              $("#from_" + selectid).find("#text_pic_form").find(".text-size button:eq(0)").text(fontsize);
              
              var alignment,alignmenttext;

              alignment=response[0].children[i].children[0].fontalign=="0"?"left":"center";
              alignmenttext=response[0].children[i].children[0].fontalign=="0"?"左对齐":"居中";
              $("#from_" + selectid).find(".alignmenttext").html("<span val='"+alignment+"'>"+alignmenttext+ "</span>"); 

            
              
             init();
             Canvasfont();
            
            }
           

           

            // $("#from_" + selectid).find("#texttype").val(response[0].children[i].children[0].advancedid);
            $("#from_" + selectid).find("#txt").val(response[0].children[i].children[0].text);


            // var text = response[0].children[i].children[0].text.toString().replace("↵", "\n")
           
          

            $("#from_" + selectid).find("#alignment").val(response[0].children[i].children[0].fontalign);
            if ($("#from_" + selectid).find("#alignment").val() == "0") {

              $("#program_" + selectid).css("display", "");
              $("#program_" + selectid).css("align-items", "");
            }
            if ($("#from_" + selectid).find("#alignment").val() == "2") {
              $("#program_" + selectid).css("display", "grid");
              $("#program_" + selectid).css("align-items", "flex-end");
            }
            if ($("#from_" + selectid).find("#alignment").val() == "1") {

              $("#program_" + selectid).css("display", "grid");
              $("#program_" + selectid).css("align-items", "center");

            }

            $("#program_" + selectid).css("white-space", "pre-wrap");
            $("#from_" + selectid).find("#fontsizediv").show();
        //  textcanvas(selectid);
          }
          
          
          //计时
          if (response[0].children[i].type==5) {
           
            $("#program_" + selectid).css("width", response[0].children[i].width + "px");
            $("#program_" + selectid).css("height", response[0].children[i].high + "px");

            $("#program_" + selectid).css("top", response[0].children[i].top + "px");
            $("#program_" + selectid).css("left", response[0].children[i].lef + "px");
            
            //alert(response[0].children[i].children[0].text);
            var regtext = new RegExp(/\↵/g, "g");  //全文匹配
            var text = response[0].children[i].children[0].text.toString().replace(regtext, "\n");

          //  $("#program_" + selectid).append(text);
           
           
            //chen，预览
            $("#program_" + selectid).css("word-wrap", "break-word").css("word-break", "break-all");
        
            $("#program_" + selectid).css("color", fontcolorval(response[0].children[i].children[0].fontcolor));


            $("#from_" + selectid).find("#left").val(response[0].children[i].lef);

            $("#from_" + selectid).find("#top").val(response[0].children[i].top);

            $("#from_" + selectid).find("#width").val(response[0].children[i].width);

            $("#from_" + selectid).find("#high").val(response[0].children[i].high);
           

            $("#from_" + selectid).find("#intype").val(response[0].children[i].children[0].intype);

            $("#from_" + selectid).find("#inspeed").val(response[0].children[i].children[0].inspeed);
          
            $("#from_" + selectid).find("#fontcolor").val(fontcolorval(response[0].children[i].children[0].fontcolor));
            
            // alert(response[0].children[i].children[0].fontsize);
            $("#from_" + selectid).find("#fontsizeadd").val(response[0].children[i].children[0].fontsize);
           
            $("#program_" + selectid).css("line-height", "1");
            console.log($("#from_" + selectid).find("#fontsizeadd").find("option:selected").text());
            var fontsize = $("#from_" + selectid).find("#fontsizeadd").find("option:selected").text().split("*");

            $("#program_" + selectid).css("font-size", fontsize[1] + "px");

            $("#from_" + selectid).find("#backcolor").val(fontcolorvaltow(response[0].children[i].children[0].backcolor));

            // alert(response[0].children[i].children[0].backcolor);

            //alert(response[0].children[i].children[0].fontsize);

            $("#from_" + selectid).find("#staytime").val(response[0].children[i].children[0].staytime);

           
            $("#from_" + selectid).find("#type").val(parseInt(response[0].children[i].type));

            $("#from_" + selectid).find("#FTPurl").val(response[0].children[i].children[0].FTPurl);
            $("#from_" + selectid).find("#size").val(response[0].children[i].children[0].size);
            $("#from_" + selectid).find("#materialid").val(response[0].children[i].children[0].materialid);

            if (response[0].children[i].children[0].txtpath == null || response[0].children[i].children[0].txtpath == "null") {
              $("#from_" + selectid).find("#txtpath").val("");
            } else {
              $("#from_" + selectid).find("#txtpath").val(response[0].children[i].children[0].txtpath);
             
            }
            // $("#from_"+selectid).find("#Dazzle,#randomFontColor").parent().show();
            $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", "");
            console.log("advancedid值" + response[0].children[i].children[0].advancedid);
            $("#from_" + selectid).find("#reckonType").val(response[0].children[i].children[0].text.playType)
           //目标时间
            var targetTime=response[0].children[i].children[0].text.baseDate+" "+response[0].children[i].children[0].text.baseTime;
            $("#from_" + selectid).find("#targetTime").val(targetTime)

            //word 电脑字体
            $("#from_" + selectid).find("#texttype").parent().hide();
            if (response[0].children[i].children[0].advancedid == "6") {
              // $("#from_"+selectid).find("#alignment").parent().show();
              //$("#from_"+selectid).find("#fontcolordiv,#fontsizediv,#fosizeval").hide();
              $("#from_" + selectid).find("#alignment").parent().hide();
              $("#from_" + selectid).find("#typefaceval").parent().hide();
              $("#from_" + selectid).find("#randomFontColor").parent().hide();
              $("#from_" + selectid).find("#Dazzle").parent().hide();
              $("#from_" + selectid).find("#fontsizeadd").parent().hide();
              $("#from_" + selectid).find("#texttype").val("1");
              $("#from_" + selectid).find("#text_pic_form").show();
              //字体大小值
              var fontsize=response[0].children[i].children[0].fontsize;
              if(fontsize=="1"){
                fontsize=16;
              }else if(fontsize=="2"){
                fontsize=24;
              }
              else if(fontsize=="3"){
                fontsize=32;
              }
              else if(fontsize=="4"){
                fontsize=12;
              }
              $("#from_" + selectid).find("#text_pic_form").find(".text-size button:eq(0)").text(fontsize);
              
              var alignment,alignmenttext;

              alignment=response[0].children[i].children[0].fontalign=="0"?"left":"center";
              alignmenttext=response[0].children[i].children[0].fontalign=="0"?"左对齐":"居中";
              $("#from_" + selectid).find(".alignmenttext").html("<span val='"+alignment+"'>"+alignmenttext+ "</span>"); 

              $("#from_" + selectid).find(".timetext span").attr("val",response[0].children[i].children[0].text.format);
           
              
             init();
             Canvasfont();
            
            }
           

           

            // $("#from_" + selectid).find("#texttype").val(response[0].children[i].children[0].advancedid);
           


            // var text = response[0].children[i].children[0].text.toString().replace("↵", "\n")
           
          

            $("#from_" + selectid).find("#alignment").val(response[0].children[i].children[0].fontalign);
            if ($("#from_" + selectid).find("#alignment").val() == "0") {

              $("#program_" + selectid).css("display", "");
              $("#program_" + selectid).css("align-items", "");
            }
            if ($("#from_" + selectid).find("#alignment").val() == "2") {
              $("#program_" + selectid).css("display", "grid");
              $("#program_" + selectid).css("align-items", "flex-end");
            }
            if ($("#from_" + selectid).find("#alignment").val() == "1") {

              $("#program_" + selectid).css("display", "grid");
              $("#program_" + selectid).css("align-items", "center");

            }

            $("#program_" + selectid).css("white-space", "pre-wrap");
            $("#from_" + selectid).find("#fontsizediv").show();
        //  textcanvas(selectid);
          }
          
          else {

            //  console.log($("#from_"+selectid).find("#txtpath").val());
            if (sessionStorage.getItem("type") == "0" || sessionStorage.getItem("type") == "1") {
              $("#texttype option[value='1']").hide()

              $("#from_" + selectid).find("#typefaceval").attr("disabled", true);

            }
            // var _uat = navigator.userAgent;
            // if (_uat.indexOf("Firefox") > 0) {
            //   $("#texttype option[value='1']").remove()

            //   $("#container" + selectid).hide();
            //   //#fontcolordiv,
            //   $("#fontsizediv,#fosizeval").show();

            // }
          }

          material_index = response[0].children[i].children[0].material_index;
          //alert(material_index);
          zeroindex = response[0].children[i].zeroindex;

          
        }
        //partitioncz();
      

      } catch (ex) {
// alert(ex);
      }
    }
      setTimeout(function () {
       
        $("#error").html("");
        $("#material li").each(function (i) {
          // alert($("#from_"+$(this).attr("id")).find("#txtpath").val());
          var _this = $(this).attr("id");
         
          //$("#from_"+$(this).attr("id")).find("#texttype").attr("disabled",true);
          //   alert($("#from_" + $(this).attr("id")).find("#texttype").val());
          if ($("#from_" + $(this).attr("id")).find("#type").val() != "1"||$("#from_" + $(this).attr("id")).find("#type").val() == "2") {
           
            if ($("#from_" + $(this).attr("id")).find("#txtpath").val().length == 0) {

             
              // $('#container'+_this).hide();
              $("#from_" + $(this).attr("id")).find("#fosizeval").show();
              $('#container' + _this).hide();

            }

            if ($("#from_" + $(this).attr("id")).find("#txtpath").val().length > 0 && $("#from_" + $(this).attr("id")).find("#texttype").val() == "0") {
              console.log("来了dfdfdrsfs")
              // alert($("#from_" + $(this).attr("id")).find("#txtpath").val());
              //$("#from_"+selectid)
              //console.log($(this).attr("id"));
              $("#from_" + _this).find("#texttype").val(0);
              $.ajax({
                type: 'POST',
                url: domain.testUrl + "/Threeinjection/programManagement/readTxTFile",
                data: { "txtpath": $("#from_" + $(this).attr("id")).find("#txtpath").val(), sessionid: sessionStorage.getItem("sid") },
                
                success: function (response) {
                  //   alert(response);   
                  // console.log($(this).attr("id")).find("#txtpath").val();
                  // alert($("#container"+selectid).html());
                  var html = response;
                  //chen
                  $("#program_" + _this).html("<div  style='width:inherit;font-family:monospace'>" + html + "</div>" + "<input type='hidden' id='imgDataURL'><input type='hidden' id='leftdw' value=" + $("#program_" + _this).find("#leftdw").val() + ">");
                  $("#program_" + _this).css("line-height", "1");
                  //"container"+_this
                  $('#container' + _this).hide();
                  //$("#from_"+_this).find("#fosizeval").val();
                  $("#from_" + _this).find("#fosizeval").show();
                 // $("#from_" + _this).find("#fontcolordiv").show();
                  $("#from_" + _this).find("#fontsizediv").show();
                  $("#from_" + _this).find("#fosizeval").val(html);
                  new ZResize({
                    stage: "#program", //舞台 
                    item: '#program_' + _this, //可缩放的类名 
                  });
                }
              });
            } else {
              console.log("来了dfdfdrsfs")
              // UE.getEditor('container'+_this).setContent(""+$("#from_"+$(this).attr("id")).find("#txt").val()+"",true);
              if ($("#from_" + $(this).attr("id")).find("#texttype").val() == "1") {
            
                $.ajax({
                  type: 'POST',
                  url: domain.testUrl + "/Threeinjection/programManagement/readTxTFile",
                  data: { "txtpath": $("#from_" + $(this).attr("id")).find("#txtpath").val(), sessionid: sessionStorage.getItem("sid") },
                  success: function (response) {
                    // console.log($(this).attr("id")).find("#txtpath").val();
                    // alert($("#container"+selectid).html());
                    var html = response;
                    //#fontcolordiv,
                   // $("#fontsizediv,#fosizeval").hide();
                    $("#program_" + _this).css("line-height", "");
                    $("#from_" + _this).find("#fosizeval").val("");
                    
               
                  
                  
                    $("#from_" + _this).find("#editor").html(html);
                    
                   if($("#from_" + _this).find("#type").val() == "3"){
                  //   //%Y转当前时间
                
                    var namenode = "";
                    var nameyear, namehour, nameday = "";
                    $("#from_" + _this).find('#editor input').each(function (i) {
                      namenode = $("#from_" + _this).find('#editor input').eq(i);
                      // console.log("格式值h"+i)
                    //  alert(namenode.attr("format"));   
                      if (namenode.attr("name") == "year") {
                        
                        nameyear = writeCurrentDate(1, namenode.attr("format"), 2);
                        namenode.attr("value", nameyear);
                      }
                      if (namenode.attr("name") == "day") {

                        nameday = writeCurrentDate(2, namenode.attr("format"), 2);
                        namenode.attr("value", nameday);
                      }
                      if (namenode.attr("name") == "hour") {

                        namehour = writeCurrentDate(3, namenode.attr("format"), 2);

                        namenode.attr("value", namehour);
                      }
                    })
                  // $("#from_" + _this).find('#editor input').val().replace(RegExp("&ensp;", "g"), " ");
    
                  }
                   
                  if($("#from_" +_this).find("#type").val() == "5"){
                   
                    var time = $("#from_" + _this).find("#targetTime").val();
                    $("#from_" + _this).find(".timetext span").text($("#from_" + _this).find("#editor input[name='dowNum']").attr("format"));
                    var numDown=writeCounDownDate(parseInt($("#from_" + _this).find("#reckonType").val()), $("#from_" + _this).find(".timetext span").attr("val"),$("#from_" + _this).find(".timetext span").text(),time,1)
                   
                    $("#from_" + _this).find("#editor input[name='dowNum']").attr("value", numDown);
                    
                  }
                   
                    
                  // setTimeout(function(){
                     selectid=_this;
                    
                    Canvasfont();
                    $("#from_" + _this).find(".text-length").find('span').text("已输入"+html.replace(/&nbsp;/g," ").replace(/<[^>]+>/g,"").length+"字");
                    //},500);
                    // $("#program_"+_this).css("color","rgb(255, 0, 0)").css("white-space","pre").css("overflow","hidden");
                    //chen,预览
                 

                  }

                });
              } else {

                new ZResize({
                  stage: "#program", //舞台 
                  item: '#program_' + selectid, //可缩放的类名 
                });

              }
            }
          }
          console.log("那你"+$("#from_" + _this).find("#Dazzle").val());
         if($("#from_" + _this).find("#Dazzle").val()!="0"){
             $("#from_" + _this).find("#fontcolor").parent().hide();
          }
        });
        $("#material li").eq($("#material li").length - 1).click();
        $("#error").html("");
        //overlap();
        setTimeout(function () {
         $("#zoom img").eq(0).click();
       }, 800);
        
        if (sessionStorage.getItem("fsopen") != null) {
          sessionStorage.removeItem("fsopen");
          if (sessionStorage.getItem("roleId") == "1") {
            $(".confirm").click();
            $("#fsopen").click();
          }
        }
      }, 1000);

     

    }
  });
 
  // $('.time').clockTimePicker({});
  //for ( var i = 0; i < 24; i++)
  //  {
  //var opt = document.getElementById("timeid");
  //	  var min = document.getElementById("starthour");
  // $("#timeid,#starthour").append("<option id="+i+">"+i+""+"</option>");
  //}
  $("#jwidth").val(sessionStorage.getItem("width"));
  $("#jhigh").val(sessionStorage.getItem("high"));
  //$("#devicetype").val(sessionStorage.getItem("type"));
  if (sessionStorage.getItem("width") > 0) {
    $("#program").css("height", parseInt($("#jhigh").val()));
    $("#program").css("width", parseInt($("#jwidth").val()));
  }
  //节目信息 宽 高
  $("#jwidth").blur(function () {
    $("#program").css("width", $("#jwidth").val());
    //console.log($("#program div").css("left"));
    $("#program .transparent_class").each(function () {
      var reg = new RegExp("px", "g");
      if (parseInt($("#jwidth").val()) < parseInt($(this).css("width"))) {
        $("#program").css("width", $(this).css("width"));
        $('#jwidth').val($(this).css("width").replace(reg, ""));
      }
    });
    setTimeout(function (i) {
      $("#program .transparent_class").each(function (i) {
        var reg = new RegExp("px", "g");
        //$(this).css("left",'');
        //$(this).find("#leftdw").val($(this).position().left+"px".replace(reg, ""));
        //i=i+1;
        //$(".col-md-9").find(".form-inline").find("#left").val(0);
      }), 100
    });
  });
  $("#jhigh").blur(function () {
    $("#program").css("height", $("#jhigh").val());
    // $("#program div").css("height",$("#jhigh").val());
    //}
  });

  var zt = true;
  var overlapval = true;
  window.addjm = function () {
    //var  programsum=$("#program .transparent_class").length;
    //for(var i=0;i<zoomsum;i++){
    //  $("#zoom img").eq(0).click();
    //   $("#zoomsum").text("0");
    //}
    overlapval = true;
    var orderid = 1;
    if ($("#typejm").val() == "2") {
      orderid = 0;
    }
    zt = true;
    var datadd = {};
    if ($("#order").val().length == 0) {
      swal("OMG!", "请选择订单！", "error");
      return;
    }
    if ($("#programid").val() != null) {
      if ($("#programid").val().length == 0) {
        swal("OMG!", "请选择节目号", "error");
        return;
      }
    }
    if ($("#festivalname").val().length == 0) {
      swal("OMG!", "请输入节目名称", "error");
      return;
    }
    if ($("#starttime").val().length == 0) {
      swal("OMG!", "请输入播放起始日期 ", "error");
      return;
    }
    if ($("#endtime").val().length == 0) {
      swal("OMG!", "请输入播放结束日期", "error");
      return;
    }


  

    // if ($("#programPrice").val().length == 0) {
    //   swal("OMG!", "请输入价格", "error");
    //   return;
    // }
    // if ($("#programPrice").val()==0) {
    //  swal("OMG!", "输入的价格必须要大于0", "error");
    //  return;
    // }
    var date3 = new Date($("#starttime").val());
    var startTime = date3.getTime();
    var date4 = new Date($("#endtime").val());
    var endTime = date4.getTime();
    console.log("时间戳：" + startTime + ",结束：" + endTime)
    if (endTime<=startTime) {
      swal("OMG!", "播放结束日期不能小于等于播放开始日期", "error");
      return;
    }
    if ($("#material li").length == 0) {
      swal("OMG!", "请填写分区信息", "error");
      return;
    }
    $("#error").html("");
    if ($("#material li").length > 1) {
      var sum = $(".transparent_class").length - 1;
      $(".transparent_class").each(function (i) {
        var ii = i;
        if ($(".transparent_class").length > 1) {
          $(".transparent_class").each(function (i) {
            if (ii != i) {
              if (overlapdiv($(".transparent_class").eq(ii), $(".transparent_class").eq(i))) {
                overlapval = false;
                return false;
              }
            }
          });
        } else if ($(".transparent_class").length == 1) {

          if (overlapdiv($(".transparent_class").eq(ii), $(".transparent_class").eq(1))) {
            overlapval = false;
            return false;
          }
        }

        if (!overlapval) {
          $("#error").html("分区不能重叠");
          swal("OMG!", "分区不能重叠", "error");
          overlapval = false;
          return false;
        }
      });
    }
    if (!overlapval) {
      return;
    }
    var programid = parseInt($("#programid").val()) - 1;
    if (programtype == "1") {
      programid = 130;
    }
   
    var programtimeinfolist = new Array();
    //1535738400000
    //alert(startDateM);
    //return;
    
    if ($("#highTime").is(":checked")) {

      //获取周期

      var checked = new Array();
      var i=0;
      $(".select li").each(function (j) {
        if ($(this).find("input").is(":checked")) {
          if($(this).find("input").val()!==null&&$(this).find("input").val()!=""){
            checked[i] = parseInt($(this).find("input").val());
            console.log("回家 "+i+","+checked[i]);
           i++;
        
          }
        }
      });
      datadd["program"] = ({
        "programPrice": $("#programPrice").val(),
        "programtype": programtype,
        "programid": sessionStorage.getItem("programid"),
        "groupprogramid": programid,
        "order_id": orderid,
        "companyid": sessionStorage.getItem("coid"),
        "type": $("#typejm").val(),
        "starttime": $("#starttime").val() + " 00:00:00",
       // "endtime": $("#endtime").val() + " 00:00:00",
       "endtime": $("#endtime").val()+" "+"23:59:59",
        "playtime": $("#playtime").val(),
        "devicetype": $("#devicetype").val(),
        "festivalname": $("#festivalname").val(),
        "isplayvoice": $("#isplayvoice").val(),
        "playtype": $("#playtype").val(),
        "days": checked
      });

      //获取时段的值
      var stime = ""; var etime = "";
      var sArr = ['']; var eArr = [''];
      var liveId=0;
     
      for (var i = 0; i < $("#liveCount").val(); i++) {
        var ii = parseInt(i) + 1;
        stime = "";//到下一轮清空
        etime = "";
        
        $("#liveStart" + ii).find("input[type='text']").each(function (i) {
          stime += $(this).val();
         

            liveId=$("#liveStart" + ii).attr("liveId");
          
        
        });
        $("#liveEnd" + ii).find("input[type='text']").each(function (i) {
          etime += $(this).val();
        });
        sArr[i] = stime+":00";
        eArr[i] = etime+":00";
        //if (i == 0) {
          // "timeid": "0", "orderid": $("#order").val()
         
            programtimeinfolist.push({
              
              "starthour": sArr[i], "endhour": eArr[i]
              
            });
          
          console.log("时间段:" + JSON.stringify(programtimeinfolist));

        // jsonval.push({ "start": sArr[i], "end": eArr[i] });
        if (getNowFormatDate() + " " + sArr[i] >= getNowFormatDate() + " " + eArr[i]) {

          swal("error!", "开始时间不能大于或等于结束时间！", "error");
          return false;
        }
 
        if (i >= 1) {
          if (getNowFormatDate() + " " + sArr[i] <= getNowFormatDate() + " " + eArr[i - 1]) {

            swal("error!", "第" + ii + "个开始时间不能小于或等于上一个结束时间！", "error");
            return false;
          }
          if (getNowFormatDate() + " " + sArr[i] <= getNowFormatDate() + " " + sArr[i - 1]) {

            swal("error!", "第" + ii + "个时间段开始不能小于或等于上一个时间段！", "error");
            return false;
          }
          if (getNowFormatDate() + " " + eArr[i] <= getNowFormatDate() + " " + eArr[i - 1]) {
            //console.log("mj"+eArr[i])
            swal("error!", "第" + ii + "个时间段结束不能小于或等于上一个时间段！", "error");
            return false;
          }
        
      

        }

      }
     
     
    } else {
      programtimeinfolist.push(
        // {"starthour": "00:00:00","endhour": "23:59:00"}
        );
      datadd["program"] = ({
        "programPrice": $("#programPrice").val(),
        "programtype": programtype,
        "programid": sessionStorage.getItem("programid"),
        "groupprogramid": programid,
        "order_id": orderid,
        "companyid": sessionStorage.getItem("coid"),
        "type": $("#typejm").val(),
        "starttime": $("#starttime").val() + " 00:00:00",
        "endtime": $("#endtime").val() + " 23:59:59",
        "playtime": $("#playtime").val(),
        "devicetype": $("#devicetype").val(),
        "festivalname": $("#festivalname").val(),
        "isplayvoice": $("#isplayvoice").val(),
        "playtype": $("#playtype").val()
  
      });
    }


    var programzeroinfo = new Array();
    var materialinfo = new Array();
    var j = 0;
    $(".col-md-9").find(".form-inline").each(function (i) {
      if (i > 1) {
        j++;
        var typeNum=$(this).find("#type").val();
        if($(this).find("#type").val()=="3"){
          typeNum=parseInt(typeNum)+1;
        }
        
        //type
        // alert($(this).find("#type").val());
        console.log("left:" + $(this).find("#left").val());
        programzeroinfo.push({
          "companyid": sessionStorage.getItem("coid"),
          "zeroindex": j,
          "devicetype": $("#devicetype").val(),
          "type":typeNum,
          "left": $(this).find("#left").val(),
          "top": $(this).find("#top").val(),
          "width": $(this).find("#width").val(),
          "high": $(this).find("#high").val(),
          "order_id": $("#order").val()
        });
        i = i - 2;
        var typetext = $("#material li a").eq(i).text();
        var type = 2;
        if (typetext == " 文本") {
          type = 0;
        }
        if (typetext == " 图片") {
          type = 1;
        }
        if (typetext == " 时间") {
          type = 3;
        }
        if (typetext == " 计时") {
          type = 5;
        }

        var size = "0";
        if (type == 1) {
          var spid = $(this).attr("id").split('_');
          if ($("#program_" + spid[1]).find("img").length == 0) {

            zt = false;
            swal("OMG!", "请检测分区无法上传空图片", "error");
            return false;
          }
          size = 0;
        }
        if (type == 2) {
          var spid = $(this).attr("id").split('_');
          if ($("#program_" + spid[1]).find("img").length == 0) {
            zt = false;
            swal("OMG!", "请检测分区无法上传空动画", "error");
            return false;
          }
          var img = $("#gifwidepth").val().split('*');
          if (parseInt(img[0]) > parseInt($(this).find("#width").val()) || parseInt(img[1]) > parseInt($(this).find("#high").val())) {
            swal("OMG!", "动画不能超过分区宽高,动画尺寸为：" + img[0] + "*" + img[1], "error"); zt = false;
            return false;
          }
          size = 0;
        }
        if(type!=2){
        if(sessionStorage.getItem("type")=="0"||sessionStorage.getItem("type")=="1"){
                      if (parseInt($(this).find("#inspeed").val())<1||parseInt($(this).find("#inspeed").val())>50) {
                        swal("OMG!", "单双色的进入速度范围在1~50，请重新输入", "error");
                        zt = false;
                        return false;
                      }
                    }else{
                    if (parseInt($(this).find("#inspeed").val())<1||parseInt($(this).find("#inspeed").val())>9) {
                      swal("OMG!", "进入速度范围在1~9，请重新输入", "error");
                      zt = false;
                      return false;
                    }
                  }
        }

        var fontcolor = typeof ($(this).find("#fontcolor").val()) != "undefined" ? $(this).find("#fontcolor").get(0).selectedIndex : 0;
        var backcolor = $(this).find("#backcolor").get(0).selectedIndex;
          
          //时间分区
          if (type == 3) {
        
            var regtext = new RegExp(/\"/g, "g");
            var fosizeval = $(this).find("#fosizeval").val().replace(regtext, "”");
            var spid = $(this).attr("id").split('_');
             //清空时间值
            var nameyear=$(this).find('#editor input[name=year]').val();
            var namehour=$(this).find('#editor input[name=hour]').val();
            var nameday=$(this).find('#editor input[name=day]').val();
  
             $(this).find('#editor input[name=year]').attr("value","");
             $(this).find('#editor input[name=hour]').attr("value","");
             $(this).find('#editor input[name=day]').attr("value","");
            var html = $(this).find("#editor").html();
            //时间节目
            if ($(this).find("#type").val() == "3") {
              if (html.trim() == "") {
                swal("OMG!", "请检测分区文本不能为空", "error");
                zt = false;
                return false;
              }
            }
         
            var textHtml=html;//html值
            //替换
            html=html.replace(/<br>/g, "\n").replace(/&nbsp;/g, "\t");
            html = html.replace(RegExp("<font color=\"#ff0000\" face=\"SimSun\"></font>", "g"), "");
            html =html.replace(RegExp("</div>", "g"), "");
            html=html.replace(/<div>/g, "\n");
            html =html.replace(RegExp("<input type=\"text\" format=\"", "g"), "");
            html =html.replace(RegExp(" name=\"year\" readonly=\"\" value=\"\"", "g"), "");
            html =html.replace(RegExp("<input type=\"text\" name=\"day\" format=\"", "g"), "");
           html =html.replace(RegExp(" readonly=\"\" value=\"\" class=\"week\"", "g"), "");
           html =html.replace(RegExp("<input type=\"text\" name=\"hour\" format=\"", "g"), "");
           html =html.replace(RegExp(" readonly=\"\" value=\"\"", "g"), "");
            html =html.replace(RegExp("\">", "g"), "");
            // html =html.replace(RegExp("&ensp;", "g"), " ");
             $(this).find('#editor input[name=year]').attr("value",nameyear);
             $(this).find('#editor input[name=hour]').attr("value",namehour);
             $(this).find('#editor input[name=day]').attr("value",nameday);
            // alert(html);
          //  console.log("测试"+html+"\n"+textHtml);
           // <input type="text" name="day" format="星期%w2" readonly="" value="" class="week
            //   zt = false;
            // return;
            //alert(html.length);//alert($(this).find("#fosizeval").val().length);
            var fontsize=$(this).find("#text_pic_form").find(".text-size button:eq(0)").text();
            if(fontsize=="12"){
              fontsize=4;
            }else if(fontsize=="16"){
              fontsize=1;
            }
            else if(fontsize=="24"){
              fontsize=2;
            }
            else if(fontsize=="32"){
              fontsize=3;
            }
            if ( parseInt($(this).find("#fosizeval").val().length) > 200) {
              swal("OMG!", "输入内容超过了限制范围", "error"); zt = false;
              return false;
            }
            if (parseInt(html.length) > 100){
              swal("OMG!", "输入内容超过了限制范围", "error");
               zt = false;
              return false;
            }
            var testsize = $(this).find("#fontsizeadd").find("option:selected").text().split("*");
            if (parseInt($(this).find("#width").val()) < parseInt(testsize[0])) {
              swal("OMG", "分区的宽度不能小于字体的大小！", "error"); zt = false;
              return false;
  
            }
            if (parseInt($(this).find("#high").val()) < parseInt(testsize[0])) {
              swal("OMG", "分区的高度不能小于字体的大小！", "error"); zt = false;
              return false;
  
            }
            if($(this).find('#editor').html().indexOf("name=")==-1){
              swal("OMG", "时间分区必须要选一个时间！", "error");
               zt = false;
              return false;
            }
            // if (parseInt($(this).find("#inspeed").val())<1||parseInt($(this).find("#inspeed").val())>9) {
            //   swal("OMG!", "进入速度范围在1~9，请重新输入", "error");
            //   zt = false;
            //   return false;
            // }

            var imgbase = $("#from_" + spid[1]).find("#imgDataURL").val();
            var edui32_button_body = $("#from_" + spid[1]).find(".edui-for-fontsize").find(".edui-box").html() + "14px";
            var reg = new RegExp("px", "g");
            edui32_button_body = edui32_button_body.replace(reg, "");
            if ($(this).find("#texttype").val() != "1") {
              imgbase = "";
              if (edui32_button_body == "字号") {
                edui32_button_body = 14;
              }
            } else {
              edui32_button_body = 0;
            }
            var textflag = 0;
            if (parseInt($("#_" + spid[1]).outerHeight()) > parseInt($("#program_" + spid[1]).outerHeight())) {
              textflag = 1;
            }
            //console.log(textflag)
            //imgbase=imgbase.substr(imgbase.indexOf(',') + 1);
            materialinfo.push({
              "companyid": sessionStorage.getItem("coid"),
            "materialid": $(this).find("#materialid").val() == "" ? 0 : $(this).find("#materialid").val(),
            //"zeroindex":j,	model this
            "fontName": $(this).find("#typefaceval option:selected").attr("id"),
            "fontAlign": $(this).find("#texttype").val()=="1"? $(this).find(".alignmenttext span").attr("val")=="left"?0:1:0,
              "text":html,//装协议值
              "htmlTxt":textHtml,//html
              "type":0,
              "devicetype": $("#devicetype").val(),
            "path": $(this).find("#FTPurl").val(),
            "size": parseInt(size),
            "model": 1,
            "intype": $(this).find("#intype").val(),
            "inspeed": $(this).find("#inspeed").val(),
            "fontcolor": typeof ($(this).find("#fontcolor").val()) == "undefined" ? 0 : fontcolor == "-1" ? 0 : fontcolor,
            //"fontsize":edui32_button_body,
            "fonteffect": $(this).find("#Dazzle").val(),
            "fontsize": fontsize,
             // "staytime": $(this).find("#staytime").val(),
  
            //  "staytime":$(this).find("#texttype").val()=="1"&&intypeval.indexOf($(this).find("#intype").val())!=-1?$(this).find("#staytime").val():0,
  
            // "staytime":$(this).find("#texttype").val()=="1"&&intypeval.indexOf($(this).find("#intype").val())!=-1?$(this).find("#staytime").val():$(this).find("#texttype").val()=="0"?$(this).find("#staytime").val():0,
            "staytime":$(this).find("#staytime").val(),

            "order_id": $("#order").val(),
            "zeroindex": j,
            "randomFontColor": $(this).find("#randomFontColor").val(),
              "randomFontColor": $(this).find("#randomFontColor").val(),
              "advancedid":5,
              "imgbase":"",
              "textflag": $(this).find("#txtpath").val(),
            });
  
  
          }
          //计时分区
          if (type == 5) {
        
          
            var spid = $(this).attr("id").split('_');
             //清空时间值
             var namedowNum=$(this).find('#editor input[name=dowNum]').val();
         

             $(this).find('#editor input[name=dowNum]').attr("value","");
             
            var html = $(this).find("#editor").html();
            //时间节目
            if ($(this).find("#type").val() == "5") {
              if (html.trim() == "") {
                swal("OMG!", "请检测分区文本不能为空", "error");
                zt = false;
                return false;
              }
            }
            var textHtml=html;//html值
            //替换
            html=html.replace(/<br>/g, "\n").replace(/&nbsp;/g, "\t");
            html = html.replace(RegExp("<font color=\"#ff0000\" face=\"SimSun\"></font>", "g"), "");
            html =html.replace(RegExp("</div>", "g"), "");
            html=html.replace(/<div>/g, "\n");
            html =html.replace(RegExp("<input type=\"text\" format=\"", "g"), "");
            html =html.replace(RegExp(" name=\"dowNum\" readonly=\"\" value=\"\"", "g"), "");
  
           html =html.replace(RegExp(" readonly=\"\" value=\"\"", "g"), "");
           html =html.replace(RegExp("\">", "g"), "");
            html =html.replace(RegExp("&ensp;", "g"), " ");
             $(this).find('#editor input[name=dowNum]').attr("value",namedowNum);
             var titleText=""; var tailText="";
            
             var titleIndex=parseInt(textHtml.indexOf("<"));
             var tailIndex=parseInt(textHtml.indexOf(">"));
          //   alert(tailIndex)
             if(textHtml.indexOf("dowNum")!="-1"){
             
              if(titleIndex!=0){
              titleText=textHtml.substring(0,titleIndex);
             
              }
              if(tailIndex!=textHtml.length-1){
                tailText=textHtml.substring(tailIndex+1);
                }
             }
             var etime = "";
             $(this).find("#baseTime").find("input[type='text']").each(function (i) {
              etime += $(this).val();
          });
         
          for(var a=1;a<=2;a++){
            var textNode=a%2!=0?titleText:tailText;
            textNode= textNode.replace(/&nbsp;/g, "\t");
            textNode=textNode.replace(/<br>/g, "\n").replace(/&nbsp;/g, "\t");
            textNode = textNode.replace(RegExp("<font color=\"#ff0000\" face=\"SimSun\"></font>", "g"), "");
            textNode =textNode.replace(RegExp("</div>", "g"), "");
            textNode=textNode.replace(/<div>/g, "\n");
            textNode =textNode.replace(RegExp("&ensp;", "g"), " ");
          if(a%2!=0){
            titleText=textNode;
          }else{
            tailText=textNode;
          }
          }
         var tarDate=$(this).find("#targetTime").val();
         var tarTime=tarDate.substring(10);
         tarDate=tarDate.substring(0,10);
        //  alert("date"+tarDate.trim()+";time"+tarTime.trim())
        
       //titleText:开头内容;tailText:结尾内容baseDate: 2020-04-17,baseTime: 00:00:01,isPlanTime: 0,0普通节目显示，1一直显示format:格式类型(1,8,15),playType: 计时类型(0为正计时，1为倒计时), formatMax: 3(1,2,3)	最大位数
           var textJson={
            "titleText":titleText,
            "tailText":tailText,
            "baseDate":tarDate.trim(),
            "baseTime": tarTime.trim(),
            "isPlanTime":0,
            "format": $(this).find(".timetext span").attr("val"),
            "playType": parseInt($(this).find("#reckonType").val()),
            "formatMax": 3
           }
          // alert(textHtml+"\n"+ JSON.stringify(textJson))
           
            // alert(html);
          //  console.log("测试"+html+"\n"+textHtml);
           // <input type="text" name="day" format="星期%w2" readonly="" value="" class="week
            //   zt = false;
            // return;
            //alert(html.length);//alert($(this).find("#fosizeval").val().length);
            var fontsize=$(this).find("#text_pic_form").find(".text-size button:eq(0)").text();
            if(fontsize=="12"){
              fontsize=4;
            }else if(fontsize=="16"){
              fontsize=1;
            }
            else if(fontsize=="24"){
              fontsize=2;
            }
            else if(fontsize=="32"){
              fontsize=3;
            }
            if ( parseInt($(this).find("#fosizeval").val().length) > 200) {
              swal("OMG!", "输入内容超过了限制范围", "error"); zt = false;
              return false;
            }
            if (parseInt(html.length) > 100){
              swal("OMG!", "输入内容超过了限制范围", "error");
               zt = false;
              return false;
            }
            var testsize = $(this).find("#fontsizeadd").find("option:selected").text().split("*");
            if (parseInt($(this).find("#width").val()) < parseInt(testsize[0])) {
              swal("OMG", "分区的宽度不能小于字体的大小！", "error"); zt = false;
              return false;
  
            }
            if (parseInt($(this).find("#high").val()) < parseInt(testsize[0])) {
              swal("OMG", "分区的高度不能小于字体的大小！", "error"); zt = false;
              return false;
  
            }
            if($(this).find('#editor').html().indexOf("name=")==-1){
              swal("OMG", "计时分区必须要选择计时格式！", "error"); zt = false;
              return false;
            }

            var d = new Date($(this).find("#targetTime").val());
          var endTime = d.getTime();
          var currentTime = new Date().getTime();
        // alert(endTime+","+currentTime)
          if (endTime <= currentTime) {
            swal("OMG!", "目标时间不能小于当前时间", "error");
            zt = false;
            return;
          }

         
         
            var imgbase = $("#from_" + spid[1]).find("#imgDataURL").val();
            var edui32_button_body = $("#from_" + spid[1]).find(".edui-for-fontsize").find(".edui-box").html() + "14px";
            var reg = new RegExp("px", "g");
            edui32_button_body = edui32_button_body.replace(reg, "");
            if ($(this).find("#texttype").val() != "1") {
              imgbase = "";
              if (edui32_button_body == "字号") {
                edui32_button_body = 14;
              }
            } else {
              edui32_button_body = 0;
            }
            var textflag = 0;
            if (parseInt($("#_" + spid[1]).outerHeight()) > parseInt($("#program_" + spid[1]).outerHeight())) {
              textflag = 1;
            }
            //console.log(textflag)
            //imgbase=imgbase.substr(imgbase.indexOf(',') + 1);
            materialinfo.push({
              "companyid": sessionStorage.getItem("coid"),
            "materialid": $(this).find("#materialid").val() == "" ? 0 : $(this).find("#materialid").val(),
            //"zeroindex":j,	model this
            "fontName": $(this).find("#typefaceval option:selected").attr("id"),
            "fontAlign": $(this).find("#texttype").val()=="1"? $(this).find(".alignmenttext span").attr("val")=="left"?0:1:0,
              "text":textJson,//装协议值
              "htmlTxt":textHtml,//html
              "type":0,
              "devicetype": $("#devicetype").val(),
            "path": $(this).find("#FTPurl").val(),
            "size": parseInt(size),
            "model": 1,
            "intype": $(this).find("#intype").val(),
            "inspeed": $(this).find("#inspeed").val(),
            "fontcolor": typeof ($(this).find("#fontcolor").val()) == "undefined" ? 0 : fontcolor == "-1" ? 0 : fontcolor,
            //"fontsize":edui32_button_body,
            "fonteffect": $(this).find("#Dazzle").val(),
            "fontsize": fontsize,
             // "staytime": $(this).find("#staytime").val(),
  
            //  "staytime":$(this).find("#texttype").val()=="1"&&intypeval.indexOf($(this).find("#intype").val())!=-1?$(this).find("#staytime").val():0,
            "staytime":$(this).find("#staytime").val(),
           // "staytime":$(this).find("#texttype").val()=="1"&&intypeval.indexOf($(this).find("#intype").val())!=-1?$(this).find("#staytime").val():$(this).find("#texttype").val()=="0"?$(this).find("#staytime").val():0,
            "order_id": $("#order").val(),
            "zeroindex": j,
            "randomFontColor": $(this).find("#randomFontColor").val(),
              "randomFontColor": $(this).find("#randomFontColor").val(),
              "advancedid":6,
              "imgbase":"",
              "textflag": $(this).find("#txtpath").val(),
            });
  
  
          }

        if (type == 0) {
          var regtext = new RegExp(/\"/g, "g");
          fosizeval = $(this).find("#fosizeval").val().replace(regtext, "“");
          var spid = $(this).attr("id").split('_');
          var html = $(this).find("#editor").text();
          if ($(this).find("#texttype").val() == "1" || $(this).find("#texttype").val() == "2") {
            if (html.trim() == "") {
              swal("OMG!", "请检测分区文本不能为空", "error");
              zt = false;
              return false;
            }
          } else {
            if ($(this).find("#fosizeval").val().trim() == "") {
              swal("OMG!", "请检测分区文本不能为空", "error");
              zt = false;
              return false;
            }
          }
          //alert(html.length);//alert($(this).find("#fosizeval").val().length);
          if (parseInt($(this).find("#fosizeval").val().length) > 200) {
            swal("OMG!", "输入内容超过了限制范围", "error"); zt = false;
            return false;
          }
          if (parseInt(html.length) > 100){

            swal("OMG!", "输入内容超过了限制范围", "error");
             zt = false;
            return false;
          }
          var testsize = $(this).find("#fontsizeadd").find("option:selected").text().split("*");
          if (parseInt($(this).find("#width").val()) < parseInt(testsize[0])) {
            swal("OMG", "分区的宽度不能小于字体的大小！", "error"); zt = false;
            return false;
          }
          if (parseInt($(this).find("#high").val()) < parseInt(testsize[0])) {
            swal("OMG", "分区的高度不能小于字体的大小！", "error"); zt = false;
            return false;
          }
          // if (parseInt($(this).find("#inspeed").val())<1||parseInt($(this).find("#inspeed").val())>9) {
          //   swal("OMG!", "进入速度范围在1~9，请重新输入", "error");
          //   zt = false;
          //   return false;
          // }
          var imgbase = $("#from_" + spid[1]).find("#imgDataURL").val();
          //console.log("imgbase:"+spid[1]+":"+imgbase);
          var edui32_button_body = $("#from_" + spid[1]).find(".edui-for-fontsize").find(".edui-box").html() + "14px";
          var reg = new RegExp("px", "g");
          // console.log("你"+$("#from_" + spid[1]).find(".edui-for-fontsize").find(".edui-box").html())
          edui32_button_body = edui32_button_body.replace(reg, "");

          if ($(this).find("#texttype").val() != "1") {
          //  html = UE.getEditor("container" + spid[1]).getContentTxt();
            imgbase = "";
            if (edui32_button_body == "字号") {

              edui32_button_body = 14;
            }
          } else {

            edui32_button_body = 0;
          }
          //console.log(edui32_button_body);
          var textflag = 0;
          if (parseInt($("#_" + spid[1]).outerHeight()) > parseInt($("#program_" + spid[1]).outerHeight())) {
            textflag = 1;
          }
          console.log(textflag);
          //alert($(this).find(".text-size").find("button").text());
          //console.log(imgbase);
          //imgbase=imgbase.substr(imgbase.indexOf(',') + 1);
          materialinfo.push({
            "companyid": sessionStorage.getItem("coid"),
            "materialid": $(this).find("#materialid").val() == "" ? 0 : $(this).find("#materialid").val(),
            //"zeroindex":j,	model this
            "fontName": $(this).find("#typefaceval option:selected").attr("id"),
            "fontAlign": $(this).find("#texttype").val()=="1"? $(this).find(".alignmenttext span").attr("val")=="left"?0:1:0,
            "text": $(this).find("#fosizeval").val() == "" ? $(this).find("#editor").html() : fosizeval,
            "type": type,
            "devicetype": $("#devicetype").val(),
            "path": $(this).find("#FTPurl").val(),
            "size": parseInt(size),
            "model": 1,
            "intype": $(this).find("#intype").val(),
            "inspeed": $(this).find("#inspeed").val(),
            "fontcolor": typeof ($(this).find("#fontcolor").val()) == "undefined" ? 0 : fontcolor == "-1" ? 0 : fontcolor,
            //"fontsize":edui32_button_body,
            "fonteffect": $(this).find("#Dazzle").val(),
            "fontsize": $(this).find("#texttype").val()==0?$(this).find("#fontsizeadd").val():$(this).find(".text-size").find("button").text(),
            "backcolor": backcolor == "-1" ? 0 : backcolor,
          //  "staytime": $(this).find("#staytime").val(),
          
          "staytime":$(this).find("#texttype").val()=="1"&&intypeval.indexOf($(this).find("#intype").val())!=-1?$(this).find("#staytime").val():$(this).find("#texttype").val()=="0"?$(this).find("#staytime").val():0,
            "order_id": $("#order").val(),
            "zeroindex": j,
            "randomFontColor": $(this).find("#randomFontColor").val(),
            "advancedid": $(this).find("#Dazzle").val() != "0" ? 4 : $(this).find("#texttype").val() == "1" ? 3 : 0,
            "imgbase": imgbase,
            "textflag": textflag,
            "txtpath":$(this).find("#txtpath").val(),
          });
      

          if (textflag == "0") {
            //   programzeroinfo[i].type=1;
            //   materialinfo[i].type=1;
            //  console.log(programzeroinfo[i].type+":"+ materialinfo[i].type);
          }
        } else if (type == 1) {
          var spid = $(this).attr("id").split('_');
          var _this = this;
          // if (parseInt($(this).find("#inspeed").val())<1||parseInt($(this).find("#inspeed").val())>9) {
          //   swal("OMG!", "进入速度范围在1~9，请重新输入", "error");
          //   zt = false;
          //   return false;
          // }
          $(this).find(".item").each(function (i) {
            if (typeof ($(this).find("#pathimg").val()) != "undefined") {
              if ($(this).find("#pathimg").val().length > 0) {
                // var imgPath=$(this).attr("src").split(',');
                //imgPath=imgPath[1];
                //imgPath = imgPath.substr(0, imgPath.length - 1); 
                //return;
                // imgPath=imgPath.substr(imgPath.lastIndexOf('.') + 1);
                // if(){
                //  $("#program_"+spid[1]).find("img")
                materialinfo.push({
                  "materialid": $(this).find("#materialid").val() == "" ? 0 : $(this).find("#materialid").val(),
                  "companyid": sessionStorage.getItem("coid"),
                  //"zeroindex":j,	model 
                  "text": typeof ($(_this).find("#fosizeval").val()) == "undefined" ? html : fosizeval,
                  "type": type,
                  "devicetype": $("#devicetype").val(),
                  "path": $(this).find("#pathimg").val(),
                  "size": $(this).find("#pathsize").val(),
                  "fileId": $(this).find("#fileId").val(),
                  "model": 1,
                  "intype": $(_this).find("#intype").val(),
                  "inspeed": $(_this).find("#inspeed").val(),
                  "fontcolor": typeof ($(_this).find("#fontcolor").val()) == "undefined" ? 0 : fontcolor,
                  "fontsize": typeof ($(_this).find("#fontsizeadd").val()) == "undefined" ? 0 : $(_this).find("#fontsizeadd").val(),
                  "backcolor": backcolor,
                  "staytime": $(_this).find("#staytime").val(),
                  "order_id": $("#order").val(), "zeroindex": j,
                  //"advancedid":1,
                  //"imgbase":imgbase
                });
              }
            }
          });
        } else if (type == 2) {
          var _this = this;
          if (parseInt($(this).find("#inspeed").val())<-9||parseInt($(this).find("#inspeed").val())>9) {
            swal("OMG!", "gif速度范围在-9~9，请重新输入", "error");
            zt = false;
            return false;
          }
          $(this).find(".item").each(function (i) {
            if (typeof ($(this).find("#pathimggif").val()) != "undefined") {
              if ($(this).find("#pathimggif").val().length > 0) {


                console.log($(this).find("#staytime").val());
                materialinfo.push({
                  "materialid": $(this).find("#materialid").val() == "" ? 0 : $(this).find("#materialid").val(),
                  "companyid": sessionStorage.getItem("coid"),
                  //"zeroindex":j,	model 
                  "text": typeof ($(_this).find("#fosizeval").val()) == "undefined" ? "" : fosizeval,
                  "type": type,
                  "devicetype": $("#devicetype").val(),
                  "path": $(this).find("#pathimggif").val(),
                  "size": $(this).find("#pathgifsize").val(),
                  "fileId": $(this).find("#fileId").val(),
                  "gifPlayTime": $(this).find("#giftime").val(),
                  "model": 1,
                  "intype": $(_this).find("#intype").val(),
                  "inspeed": $(_this).find("#inspeed").val(),
                  "fontcolor": typeof ($(_this).find("#fontcolor").val()) == "undefined" ? 0 : fontcolor,
                  "fontsize": typeof ($(_this).find("#fontsizeadd").val()) == "undefined" ? 0 : $(_this).find("#fontsizeadd").val(),
                  "backcolor": backcolor,
                  "staytime": $(_this).find("#staytime").val(),
                  "order_id": $("#order").val(), "zeroindex": j
                });
              }
            }
          });
        }
      }

      datadd["programtimeinfolist"] = programtimeinfolist;
      datadd["programzeroinfo"] = programzeroinfo;
      datadd["materialinfo"] = materialinfo;
    });
    //console.log("234:"+JSON.stringify(datadd["materialinfo"]));
    //return;
    //console.log(JSON.stringify(datadd));
    //alert(zt);

    if (zt) {
      if (idjm) {


        console.log(JSON.stringify(datadd));
        $.fn.jqLoading({ height: 100, width: 240, text: "正在保存中，请耐心等待...." });
        $.ajax({
          type: "POST",
          //url: "上传图片接口",
          url: domain.testUrl + "/Threeinjection/programManagement/updateProgramInfo",
          data: { "updateprogram": JSON.stringify(datadd), sessionid: sessionStorage.getItem("sid") },
          //视情况将base64的前面字符串data:image/png;base64,删除
          cache: false,
          success: function (response) {
            $.fn.jqLoading("destroy");
            // console.log(response);
            response = JSON.parse(response);
            if (response.code == "200") {
              idjm = false;

              //$("#fsopen").click();
              swal("success!", "保存成功", "success");
              //节目号


              // setTimeout(function () {
              programtype = 0;
              $("#error").html("");

              setTimeout(function () {

                //设置值来弹发送框
                sessionStorage.setItem("upfs", "cl");

                location.reload();
              }, 600);
              //在这里延迟谈的话会把弹出框给刷没，可以先谈后刷


              // zoomsum = 0;
              // $("#zoom img:eq(1)").hide();
              //  $("#zoomsum").text("0");
              //   $("#program").css("height", sessionStorage.getItem("high")).css("width", sessionStorage.getItem("width"));
              //清空分区
              //$("#material li").each(function (i) {
              // del($(this).find("img:eq(1)"));
              //$("#materialinfo li a").eq(i).click();
              // });
              //canvas();
              //location.reload();
              // }, 1500);
            }
            //修改了节目，顺便刷新下节目列表的数据
            parent.window.frames["iftab_15"].window.cxlist();
          },
          error: function (XMLHttpRequest, textStatus, errorThrown) {
            $.fn.jqLoading("destroy");
            swal("OMG!", "保存失败", "error");
          }
        });
      }
    }

  }
  var basesum = 0;
  window.basesumval = function (ths) {
    var programsum = $("#program .transparent_class").length;
    //for(var i=0;i<zoomsum;i++){
    //  $("#zoom img").eq(1).click();
    // $("#zoomsum").text("0");
    //}
    if (programsum == basesum) {
      idjm = true;
     // xywhinputval();
      setTimeout(function () {
        addjm();
      }, 800);
      // $("#addjm2").click();
      console.log("EDN");
      basesum = 0;
      return;
    }

    var fromid = $("#program .transparent_class").eq(basesum).attr("id").split('_'); var fromid = $("#program .transparent_class").eq(basesum).attr("id").split('_');
    if ($("#from_" + fromid[1]).find("#type").val() == "0") {
      var restfq = false;
      if ($("#zoomsum").text() != "0") {
        // restfq=true;
        //Restorefq($("#program .transparent_class").eq(basesum),0);
      }
   //   Restorefq($("#program .transparent_class").eq(basesum), 0);
      $("#_" + $("#material li").eq(basesum).attr("id")).find("p:eq(0)").css("line-height", "");
      $("#" + $("#program .transparent_class").eq(basesum).attr("id")).find("p:eq(0)").css("line-height", "");

      $("#" + $("#program .transparent_class").eq(basesum).attr("id")).find(".resize-panel").remove();
      //console.log($("#_"+$("#material li").eq(basesum).attr("id")).outerHeight());
      var w = $("#" + $("#program .transparent_class").eq(basesum).attr("id")).outerHeight();
      var jpgpng = 0;
      if (parseInt($("#_" + $("#material li").eq(basesum).attr("id")).outerHeight()) > parseInt(w)) {
        jpgpng = 1;
        $("#" + $("#program .transparent_class").eq(basesum).attr("id")).css("height", $("#_" + $("#material li").eq(basesum).attr("id")).outerHeight() + "px");
      }
      sessionStorage.setItem("programfq", $("#program .transparent_class").eq(basesum).attr("id"));


      $("#" + $("#program .transparent_class").eq(basesum).attr("id")).css("border", '');
      html2canvas($("#" + $("#program .transparent_class").eq(basesum).attr("id")), {
        background: "#000000",
        onrendered: function (canvas) {
          var fullQuality = "";
          console.log("jpgpng:" + jpgpng);
          if (jpgpng == 1) {

          } else {
            //  fullQuality = canvas.toDataURL("image/jpeg", 1);
          }
          $("#" + $("#program .transparent_class").eq(basesum).attr("id")).css("border", '2px dashed rgb(255, 255, 255)');
          fullQuality = canvas.toDataURL("image/png", 1);

          $("#program_" + fromid[1]).find("p:eq(0)").css("line-height", "1");
          //  console.log(fullQuality);
          // $("#festivalname").val(fullQuality);
          $("#program .transparent_class").eq(basesum).find("#imgDataURL").val(fullQuality);
          new ZResize({
            stage: "#program", //舞台 
            item: "#" + $("#program .transparent_class").eq(basesum).attr("id"), //可缩放的类名 
          });

          //console.log("#"+$("#program .transparent_class").eq(basesum).attr("id"));
          $("#" + $("#program .transparent_class").eq(basesum).attr("id")).css("height", w + "px");
        //  Restorefq($("#program .transparent_class").eq(basesum), 1);
          // if (restfq) {
          //   Restorefq($("#program .transparent_class").eq(basesum), 1);
          // }
          basesum++;
          basesumval();
        }
      });
    } else {
      basesum++;
      basesumval();
    }
  };

  //保存
  $("#addfq").click(function () {
    if (programtype != 1) {

      programtype = 0;
    }
    if(parseInt($("#zoomsum").text())>1){
      $("#zoom zoom:eq(1)").click();
    }

    var tasks=[];var jj=1;
    function output(j) { 
      var promise = new Promise( function(resolve, reject) {
        jj=jj+1;
       setTimeout(function () {
        selectid=j;
       
        $("#addfq").attr("disabled",false);
      Canvasfont(j);
      resolve(j);
       },500*jj);
      });
      promise.then(function (j) {
      });
      return promise;
    }
    $(".transparent_class").each(function (i) {
      var id = $(this).attr("id").split("_")[1];
      if($("#from_" + id).find("#texttype").val()=="1"){
      tasks.push(output(id));
      }
    });
			Promise.all(tasks).then(function () {
      console.log('Promise循环完事了');
      $("#addfq").removeAttr("disabled");
      basesumval()
			});
  //   $(".transparent_class").each(function (i) {
  //   var id = $(this).attr("id").split("_")[1];
  //   selectid=id;
  //  // alert(selectid);
  //    mycanvasadd();
  //   if(i==$(".transparent_class").length-1){
  //     setTimeout(function () {
  //       basesumval()
  //       }, 1000);
  //   }

  //   });
   
   
  });


  //添加分区
  var guid = "";
  selectid = guid;
  window.partitioncz = function (ths) {
    guid = uuid();
    selectid = guid;
    $("#material li").removeAttr("style");
    $("#material").append("<li id=" + guid + "  style=background-color:#eee;><a ><img src=" + $(ths).find("img").attr("src") + " class='img-rounded' style='width: 25px;'>" + $(ths).text() + "<img src='static/img/del.png' style='width:26px;float:right;' onclick=del(this) class='img-rounded'></a></li>");
    //alert($(".form-inline").eq(1).html());
    //<form class="form-inline" role="form" 
    //添加分区信息
    //alert($(this).text());
    $("#fqfrom").hide();
    $(".col-md-9").find(".scheduler-border").hide();
    if ($(ths).text() == " 文本") {
      //$(".col-md-9").append("<form class='form-inline' id=from_"+guid+" role='form'>"+$(".form-inline").eq(1).html()+"</from>");
      var html = $(".col-md-9").find(".form-inline").eq(0).html().replace("container", "container" + guid);
      //$(".col-md-9").append("<fieldset  class=scheduler-border style='border:none;border-top: 1px solid rgb(66, 139, 202);'><legend class='scheduler-border' style='margin-bottom: 0px'>分区信息</legend><form class='form-inline' id=from_"+guid+" role='form'>"+$(".col-md-9").find(".form-inline").eq(0).html()+"</from></fieldset>");
      //var html=$(".col-md-9").find(".form-inline").eq(0).html().replace("container","container"+guid);

      $(".col-md-9").append("<fieldset  class=scheduler-border style='border:none;border-top: 1px solid rgb(66, 139, 202);'><legend class='scheduler-border' style='margin-bottom: 0px'>分区信息</legend><form class='form-inline' id=from_" + guid + " role='form'>" + html + "</from></fieldset>");
      
   
      if (sessionStorage.getItem("type") == "0" || sessionStorage.getItem("type") == "1") {
        $("#texttype option[value='1']").hide();
        $("#fontcolordiv,#fontsizediv,#fosizeval").show();
        $("#from_" + guid).find("#typefaceval").attr("disabled", true);
      
     //  Canvasfont();

      }

      // var _uat = navigator.userAgent;
      // if (_uat.indexOf("Firefox") > 0) {
      //   $("#texttype option[value='1']").remove()

     
      //   $("#fontcolordiv,#fontsizediv,#fosizeval").show();

      // }
   
      $("#from_" + guid).find("#texttype").change(function () {
        $("#program_" + selectid).html("");

        if ($(this).val() == "1") {
          // $("#container" + selectid).show();
          $("#from_" + selectid).find("#fontcolordiv,#fontsizediv,#fosizeval").hide();
          $("#program_" + selectid).css("line-height", "");
          $("#from_" + selectid).find("#fosizeval").val("");


          $("#from_" + selectid).find("#Dazzle").parent().hide();
          $("#from_" + selectid).find("#typefaceval").parent().hide();

          $("#from_" + selectid).find("#randomFontColor").parent().hide();
          $("#from_" + selectid).find("#randomFontColor").val(0);
          $("#from_" + selectid).find("#typefaceval").val("");
          $("#from_" + selectid).find("#alignment").val("0");
          $("#from_" + selectid).find("#alignment").parent().hide();
          $("#from_" + selectid).find("#Dazzle").html("<option value='0'>无效果</option>");
          $("#from_" + selectid).find("#text_pic_form").show();
          $("#from_" + selectid).find("#targetTime,#baseTime").parent().hide();
          $("#from_" + selectid).find("#reckonType").parent().hide();
          //隐藏时间
          $("#from_" + selectid).find("#day,#week,#hour").hide();
          $("#from_" + selectid).find(".daytext,.weektext,.hourtext").parent().hide();
          $("#from_" + selectid).find("#text_pic_form").find(".timeNumSelect").parent().hide();
          init();
          Canvasfont();
        } else {

          $("#fontcolordiv,#fontsizediv,#fosizeval").show();
          $("#program_" + selectid).css("line-height", "1");
          $("#from_" + selectid).find("#fontcolor").val("red");
          $("#from_" + selectid).find("#fontsizeadd").val("1");
          $("#from_" + selectid).find("#Dazzle").parent().show();
          
          $("#from_" + selectid).find("#text_pic_form").hide();
          //   $("#fontcolordiv,#fontsizediv,#fosizeval").show();
          // $("#program_" + selectid).css("line-height", "1");
          // $("#from_" + selectid).find("#typefaceval").val("");
          // $("#from_" + selectid).find("#fontcolor").val("red");
          // $("#from_" + selectid).find("#fontsizeadd").val("1");

          // $("#from_" + selectid).find("#fontcolor").parent().show();
          // $("#from_" + selectid).find("#fontsizeadd").parent().show();

          // $("#from_" + selectid).find("#Dazzle").parent().show();
          // $("#from_" + selectid).find("#typefaceval").parent().show();
          // $("#from_" + selectid).find("#randomFontColor").parent().show();
          // $("#from_" + selectid).find("#typefaceval").trigger('change');
          // $("#from_" + selectid).find("#fosizeval").show();

        }
        new ZResize({
          stage: "#program", //舞台 
          item: '#program_' + selectid, //可缩放的类名 
        });
        //  overlap();      //字体放大
        // Fontmax();
      });

       overlap();      //字体放大
    
      $("#from_" + guid).find("#backcolor").parent().removeClass("col-sm-3");
      $("#from_" + guid).find("#backcolor").parent().addClass("col-sm-4");
      $("#from_" + guid).find("#type").val(0);
      $("#from_" + guid).find("#high").val(sessionStorage.getItem("high"));


      //默认选择文本

      $("#from_" + selectid).find("#texttype").val("0");
      $("#container" + selectid).hide();
      $("#fontcolordiv,#fontsizediv,#fosizeval").show();
      $("#program_" + selectid).css("line-height", "1");
      $(".transparent_class").css("white-space", "pre-wrap")
      //$("#from_" + selectid).find("#fontcolor").val("red");
      //$("#from_" + selectid).find("#fontsizeadd").val("1");

    }
    if ($(ths).text() == " 图片") {
      //$(".col-md-9").append("<form class='form-inline' id=from_"+guid+" role='form'>"+$(".form-inline").eq(1).html()+"</from>");
      $(".col-md-9").append("<fieldset  class=scheduler-border style='border:none;border-top: 1px solid rgb(66, 139, 202);'><legend class='scheduler-border' style='margin-bottom: 0px'>分区信息</legend><form class='form-inline' id=from_" + guid + " role='form'>" + $(".col-md-9").find(".form-inline").eq(0).html() + "</from></fieldset>");

      $("#from_" + guid).find("#texttype").parent().hide();
      $("#from_" + guid).find("#backcolor").parent().removeClass("col-sm-4");
      $("#from_" + guid).find("#backcolor").parent().addClass("col-sm-3");

      $(".transparent_class").css("white-space", " ");
      //alert($("#backcolor").parent());
      //alert(123);

      $("#from_" + guid + "").find("#fontcolor").parent().remove();
      $("#from_" + guid + "").find("#fontsizeadd").parent().remove();
      $("#from_" + guid + "").find("#fosizeval").parent().remove();

      $("#from_" + guid + "").find("#randomFontColor").parent().hide();
      //fontcolor    
      $("#from_" + guid).find("#typefaceval,#Dazzle").parent().hide();
      $("#from_" + guid + "").find("#imgadd").show();

      $("#from_" + guid + "").css("height", 230); $("#from_" + guid).find("#type").val(1);

      $("#from_" + guid).find("#width").val(sessionStorage.getItem("width"));

      $("#from_" + guid).find("#high").val(sessionStorage.getItem("high"));
      var jj = -1; var ii = -1;
      $(".col-md-9").find(".item").each(function (i) {
        if ($(this).parent().parent().parent().parent().index() > 1) {

          if ($(this).parent().parent().attr("id").toString() == "imgadd") {

            if ($(this).parent().parent().css('display') != "none") {
              ii++;
              $(this).find("#hfile1").val(ii);

            }
          }
        }
      });
      overlap();
    }
    if ($(ths).text() == " 动画") {

      //fqfrom
      $(".col-md-9").append("<fieldset  class=scheduler-border style='border:none;border-top: 1px solid rgb(66, 139, 202);'><legend class='scheduler-border' style='margin-bottom: 0px'>分区信息</legend><form class='form-inline' id=from_" + guid + " role='form'>" + $(".col-md-9").find(".form-inline").eq(0).html() + "</from></fieldset>");
      $("#from_" + guid).find("#texttype").parent().hide();
      $(".transparent_class").css("white-space", " ");
      $("#from_" + guid).find("#type").val(2);
      //alert(123);
      $("#from_" + guid).find("#typefaceval,#Dazzle").parent().hide();

      $("#from_" + guid).find("#width").val(sessionStorage.getItem("width"));

      $("#from_" + guid).find("#high").val(sessionStorage.getItem("high"));

      $("#from_" + guid + "").find("#fontcolor").parent().remove();
      $("#from_" + guid + "").find("#fontsizeadd").parent().remove();
      $("#from_" + guid + "").find("#fosizeval").parent().remove();
      //fontcolor    
      $("#from_" + guid).find("#backcolor").parent().removeClass("col-sm-4");
      $("#from_" + guid).find("#backcolor").parent().addClass("col-sm-3");
      $("#from_" + guid + "").find("#imgaddgif").show();
      $("#from_" + guid + "").find("#randomFontColor").parent().hide();
      $("#from_" + guid + "").css("height", 230);
      $("#from_" + guid + "").find("#inspeed").val(0);
      $("#from_" + guid).find("#inText").html("gif速度&ensp;&emsp;&thinsp;&zwnj;&ensp; &emsp; &thinsp; &zwnj;&zwj;&zwnj;");
      $("#from_" + guid).find(".spinner:eq(5)").parent().hide();
      $("#from_" + guid).find("#intype").parent().hide();
      //图片排列
      var jj = -1; var ii = -1;
      $(".col-md-9").find(".item").each(function (i) {
        if ($(this).parent().parent().parent().parent().index() > 1) {
          if ($(this).parent().parent().attr("id").toString() == "imgaddgif") {
            if ($(this).parent().parent().css('display') != "none") {
              ii++;
              $(this).find("#hfile2").val(ii);

            }
          }
        }
      });
      overlap();
    }

    if ($(ths).text()==" 时间") {

      //$(".col-md-9").append("<form class='form-inline' id=from_"+guid+" role='form'>"+$(".form-inline").eq(1).html()+"</from>");
  

      var html = $(".col-md-9").find(".form-inline").eq(0).html().replace("container", "container" + guid);
     
     

      //$(".col-md-9").append("<fieldset  class=scheduler-border style='border:none;border-top: 1px solid rgb(66, 139, 202);'><legend class='scheduler-border' style='margin-bottom: 0px'>分区信息</legend><form class='form-inline' id=from_"+guid+" role='form'>"+$(".col-md-9").find(".form-inline").eq(0).html()+"</from></fieldset>");
      //var html=$(".col-md-9").find(".form-inline").eq(0).html().replace("container","container"+guid);

      $(".col-md-9").append("<fieldset  class=scheduler-border style='border:none;border-top: 1px solid rgb(66, 139, 202);'><legend class='scheduler-border' style='margin-bottom: 0px'>分区信息</legend><form class='form-inline' id=from_" + guid + " role='form'>" + html + "</from></fieldset>");
      
      // $("#from_" + selectid).find("#fosizeval").hide();
    

      // var _uat = navigator.userAgent;
      // if (_uat.indexOf("Firefox") > 0) {
      //   $("#texttype option[value='1']").remove()

     
      //   $("#fontcolordiv,#fontsizediv").show();

      // }
     
     // $("#from_" + guid).find("#texttype").change(function () {
        $("#program_" + selectid).html("");
      
        $("#from_" + selectid).find("#texttype").parent().hide();
        $("#from_" + selectid).find("#texttype").val("1");
        $("#from_" + selectid).find("#fontcolordiv").show();
        $("#from_" + selectid).find("#type").val(3);  
        $("#from_" + guid).find("#high").val(sessionStorage.getItem("high"));
       
        if ($("#from_" + selectid).find("#texttype").val() == "1") {

        
          //#fontcolordiv,
          // $("#fontcolordiv,#fontsizediv,#fosizeval").hide();
         
          $("#program_" + selectid).css("line-height", "");
          $("#from_" + selectid).find("#fosizeval").val("");


          $("#from_" + selectid).find("#Dazzle").parent().hide();
          $("#from_" + selectid).find("#typefaceval").parent().hide();

          $("#from_" + selectid).find("#randomFontColor").parent().hide();
          $("#from_" + selectid).find("#randomFontColor").val(0);
          $("#from_" + selectid).find("#typefaceval").val("");
          $("#from_" + selectid).find("#alignment").val("0");
          $("#from_" + selectid).find("#alignment").parent().hide();
          $("#from_" + selectid).find("#Dazzle").html("<option value='0'>无效果</option>");
          $("#from_" + selectid).find(".text-align button").show();
          $("#from_" + selectid).find("#text_pic_form").show();
          $("#from_" + selectid).find("#targetTime,#baseTime").parent().hide();
          $("#from_" + selectid).find("#reckonType").parent().hide();
          $("#from_" + selectid).find("#text_pic_form").find(".drop_fontsize2 li").hide();
          var sizeShow=$("#from_" + selectid).find("#text_pic_form").find(".drop_fontsize2 li");
         
        //$("#from_" + selectid).find("#fosizeval").hide();
        $("#from_" + selectid).find("#fosizeval,#fontsizediv").hide();
          //隐藏
          sizeShow.eq(0).show();
          sizeShow.eq(1).show();
          sizeShow.eq(9).show();
          sizeShow.eq(17).show();
       
        //  $("#from_" + selectid).find("#fosizeval").parent().hide();
          $("#from_" + selectid).find("#text_pic_form").find(".form-group div").eq(0).hide();
          $("#from_" + selectid).find("#text_pic_form").find(".form-group div").eq(1).hide();
          $("#from_" + selectid).find("#text_pic_form").find(".timeNumSelect").parent().hide();

          setTimeout(function(){
          init();//电脑字体
            //默认给个时间
         
          Canvasfont();
          },500);
        }
         else {
     

       
          // $("#fontcolordiv,#fontsizediv,#fosizeval").show();
          // $("#program_" + selectid).css("line-height", "1");
          // // $("#from_" + selectid).find("#fontcolor").val("red");
          // //$("#from_" + selectid).find("#fontsizeadd").val("1");
          // $("#from_" + selectid).find("#typefaceval").val("");

          // $("#from_" + selectid).find("#Dazzle").parent().show();
          // //$("#from_" + selectid).find("#typefaceval").parent().show();
          // // $("#from_" + selectid).find("#randomFontColor").parent().show();
          // $("#from_" + selectid).find("#typefaceval").trigger('change');
          // $("#from_" + selectid).find("#text_pic_form").hide();

        // }
        new ZResize({
          stage: "#program", //舞台 
          item: '#program_' + selectid, //可缩放的类名 
        });
        //  overlap();      //字体放大
        // Fontmax();
   //   });

      
      $("#program_" + selectid).css("line-height", "1");
    
    }
    }
    if ($(ths).text() == " 计时") {
      //$(".col-md-9").append("<form class='form-inline' id=from_"+guid+" role='form'>"+$(".form-inline").eq(1).html()+"</from>");
      var html = $(".col-md-9").find(".form-inline").eq(0).html().replace("container", "container" + guid);
      //$(".col-md-9").append("<fieldset  class=scheduler-border style='border:none;border-top: 1px solid rgb(66, 139, 202);'><legend class='scheduler-border' style='margin-bottom: 0px'>分区信息</legend><form class='form-inline' id=from_"+guid+" role='form'>"+$(".col-md-9").find(".form-inline").eq(0).html()+"</from></fieldset>");
      //var html=$(".col-md-9").find(".form-inline").eq(0).html().replace("container","container"+guid);

      $(".col-md-9").append("<fieldset  class=scheduler-border style='border:none;border-top: 1px solid rgb(66, 139, 202);'><legend class='scheduler-border' style='margin-bottom: 0px'>分区信息</legend><form class='form-inline' id=from_" + guid + " role='form'>" + html + "</from></fieldset>");
      
      // $("#from_" + selectid).find("#fosizeval").hide();
    

      // var _uat = navigator.userAgent;
      // if (_uat.indexOf("Firefox") > 0) {
      //   $("#texttype option[value='1']").remove()

     
      //   $("#fontcolordiv,#fontsizediv").show();

      // }
     
     // $("#from_" + guid).find("#texttype").change(function () {
        $("#program_" + selectid).html("");
        $("#from_" + selectid).find("#texttype").val("1");
        $("#from_" + selectid).find("#texttype").parent().hide();
        $("#from_" + selectid).find("#fontcolordiv").show();
        $("#from_" + selectid).find("#type").val(5);
        $("#from_" + guid).find("#high").val(sessionStorage.getItem("high"));
      if($("#from_" + selectid).find("#targetTime").val()==""){
        $("#from_" + selectid).find("#targetTime").val(getNowFormatDate(1)+" 12:00:00");
        }
        if ($("#from_" + selectid).find("#texttype").val() == "1") {

        
          //#fontcolordiv,
          // $("#fontcolordiv,#fontsizediv,#fosizeval").hide();
         
          $("#program_" + selectid).css("line-height", "");
          $("#from_" + selectid).find("#fosizeval").val("");


          $("#from_" + selectid).find("#Dazzle").parent().hide();
          $("#from_" + selectid).find("#typefaceval").parent().hide();

          $("#from_" + selectid).find("#randomFontColor").parent().hide();
          $("#from_" + selectid).find("#randomFontColor").val(0);
          $("#from_" + selectid).find("#typefaceval").val("");
          $("#from_" + selectid).find("#alignment").val("0");
          $("#from_" + selectid).find("#alignment").parent().hide();
          $("#from_" + selectid).find("#Dazzle").html("<option value='0'>无效果</option>");
          $("#from_" + selectid).find(".text-align button").show();
          $("#from_" + selectid).find("#text_pic_form").show();
          
          $("#from_" + selectid).find("#text_pic_form").find(".drop_fontsize2 li").hide();
          $("#from_" + selectid).find("#text_pic_form").find("#day,#hour,#week").hide();
          $("#from_" + selectid).find("#text_pic_form input").find("#day").hide();
          $("#from_" + selectid).find("#text_pic_form").find("#hour").next().hide();
          $("#from_" + selectid).find("#text_pic_form").find("#day,#week").next().hide();
          $("#from_" + selectid).find("#text_pic_form").find(".form-group div").eq(0).hide();
          $("#from_" + selectid).find("#text_pic_form").find(".form-group div").eq(1).hide();
          $("#from_" + selectid).find("#text_pic_form").find(".form-group div").eq(4).hide();
          $("#from_" + selectid).find("#text_pic_form").find(".form-group div").eq(5).hide();
           $("#from_" + selectid).find("#text_pic_form").find(".form-group div").eq(6).hide();
          var sizeShow=$("#from_" + selectid).find("#text_pic_form").find(".drop_fontsize2 li");

          $("#from_" + selectid).find("#targetTime").parent().show();
          $("#from_" + selectid).find("#reckonType").parent().show();
          $("#from_" + selectid).find("#fosizeval,#fontsizediv").hide();
          sizeShow.eq(0).show();
          sizeShow.eq(1).show();
          sizeShow.eq(9).show();
          sizeShow.eq(17).show();
         

          setTimeout(function(){
          init();//电脑字体
          
        
          Canvasfont();
          },500);
        }
         else {
     

       
          // $("#fontcolordiv,#fontsizediv,#fosizeval").show();
          // $("#program_" + selectid).css("line-height", "1");
          // // $("#from_" + selectid).find("#fontcolor").val("red");
          // //$("#from_" + selectid).find("#fontsizeadd").val("1");
          // $("#from_" + selectid).find("#typefaceval").val("");

          // $("#from_" + selectid).find("#Dazzle").parent().show();
          // //$("#from_" + selectid).find("#typefaceval").parent().show();
          // // $("#from_" + selectid).find("#randomFontColor").parent().show();
          // $("#from_" + selectid).find("#typefaceval").trigger('change');
          // $("#from_" + selectid).find("#text_pic_form").hide();

        // }
        new ZResize({
          stage: "#program", //舞台 
          item: '#program_' + selectid, //可缩放的类名 
        });
        //  overlap();      //字体放大
        // Fontmax();
   //   });

      
      $("#program_" + selectid).css("line-height", "1");
    
    }
    }



    $("#from_" + guid).find("#type").attr("disabled", "disabled");

    $(".panel-heading").click(function () {
      $(".col-md-9").find(".scheduler-border").hide();
      $("#fqfrom").show(); $("#fqfrom").find('.scheduler-border').show();
    });

    $("#material li").eq($("#program").find(".transparent_class").length).click(function () {
      selectid = $(this).attr("id");
      html2canvas(document.querySelector("#program_" + selectid), {
        //canvas: canvas,
        async: false,
        onrendered: function (canvas) {
          //var chenc=canvas.toDataURL();
          var fullQuality = canvas.toDataURL("image/bmp", 1);
          //console.log(fullQuality);
          $("#program_" + selectid).find("#imgDataURL").val(fullQuality);
          //var  imgbase=fullQuality.substr(fullQuality.indexOf(',') + 1);
          //console.log(imgbase);
        }
      });
      //console.log($("#from_"+selectid).find("#txtpath").val());

      var indx = $(this).index();
      $("#material li").removeAttr("style");
      $(this).css("background-color", "#eee");
      //$("#fqfrom").hide();
      $(".col-md-9").find(".scheduler-border").hide();
      //$(".col-md-9").find(".form-inline").hide();
      //alert($("#from_"+selectid).parent().html());
      $("#from_" + selectid).parent().show();
      $("#from_" + selectid).parent().find('.scheduler-border').show();
      $("#program_" + selectid).css("z-index", $("#program").find("div").length);
      //重新排列分区
      //$("#material li")
      $("#material li").each(function (i) {
        var ifi = i + 1;
        if (ifi != indx) {
          $("#program_" + $(ths).attr("id")).css("z-index", i);
        }
      });

      if ($("#from_" + selectid).find("#texttype").val() == "1") {
        $("#container" + selectid).show();
        $("#from_" + selectid).find("#fontsizediv").hide();
       // $("#from_" + selectid).find("#fontcolordiv").hide();
        $("#from_" + selectid).find("#fosizeval").hide();
      } else {
        setTimeout(function () {
          $("#container" + selectid).hide();

          $("#from_" + selectid).find("#fontsizediv").show();
          $("#from_" + selectid).find("#fosizeval").show();
        }, 200);


      }




    });
    if (widthlocal == 0) {
      var fqvalue = "<div id=program_" + guid + " class='transparent_class' style='top:0px;position: absolute;z-index:" + $("#program").find("div").length + ";border:2px dashed #FFFFFF; width:" + $("#jwidth").val() + "px;height:" + $("#jhigh").val() + "px; background-color: #413d3d;'> <input type='hidden' id='leftdw'/></div>";
    } else {
      var fqvalue = "<div id=program_" + guid + " class='transparent_class' style='top:0px;position: absolute;z-index:" + $("#program").find("div").length + ";border:2px dashed #FFFFFF; width:" + widthlocal + "px;height:" + heightlocal + "px; background-color: #413d3d;'> <input type='hidden' id='leftdw'/></div>";
    }
    $("#program").append(fqvalue);





    new ZResize({
      stage: "#program", //舞台 
      item: '#program_' + guid, //可缩放的类名 
    });
    $('#from_' + selectid).find("#width").val($("#jwidth").val());

    // ("#jwidth").val()
    $('#program_' + selectid).css("background-color", $('#from_' + selectid).find("#backcolor").val());

    //alert($('#program_'+selectid).position().left);



    var leftwz = $('#program_' + selectid).position().left + "px";


    var reg = new RegExp("px", "g");
    leftwz = leftwz.replace(reg, "");

    $('#program_' + selectid).find("#leftdw").val(leftwz);



    //$( "#draggable3" ).draggable({  });
    //var  counts = [ 0, 0, 0 ];
    //$('#program_'+selectid).draggable({
    //containment: "#program", scroll: false,
    //  start: function() {
    // var  valid=$(this).attr("id");
    // valid=valid.split('_');
    //  alert(valid[1]);
    //console.log();
    //selectid=valid[1];
    //	counts[ 0 ]++;
    //	console.log($(this).attr("id"));
    // updateCounterStatus( $start_counter, counts[ 0 ] );
    // },
    //   drag: function() {
    //counts[ 1 ]++;
    //console.log($('#program_'+selectid).css("left"));
    //},
    // stop: function() {

    //	counts[ 2 ]++;
    //var left=$('#program_'+selectid).css("left");

    //var top=$('#program_'+selectid).css("top");

    //var reg = new RegExp("px","g");
    //left = left.replace(reg, "");

    //alert($('#program_'+selectid).find("#leftdw").val());
    //alert($('#program_'+selectid).find("#leftdw").val());

    //left=parseInt(left)-parseInt($('#program_'+selectid).find("#leftdw").val());


    //left=parseInt(left)-parseInt(leftwz);
    //$('#from_'+selectid).find("#left").val(left);
    //top = top.replace(reg, "");

    //$('#from_'+selectid).find("#top").val(parseInt(top));
    //} 
    //});
    //节目信息分区 宽 高
     $('#from_' + selectid).find("#inspeed").blur(function () {
            if ($('#from_' + selectid).find("#type").val() != "2") {
              if ($(this).val() == "") {
      
                $(this).val(1);
              }
              if (sessionStorage.getItem("type") == "0" || sessionStorage.getItem("type") == "1") {
                if (parseInt($('#from_' + selectid).find("#inspeed").val()) < 1 || parseInt($('#from_' + selectid).find("#inspeed").val()) > 50) {
                  swal("OMG!", "单双色的进入速度范围在1~50，请重新输入", "error");
                  zt = false;
                  return false;
                }
              } else {
                if (parseInt($('#from_' + selectid).find("#inspeed").val()) < 1 || parseInt($('#from_' + selectid).find("#inspeed").val()) > 9) {
                  swal("OMG!", "进入速度范围在1~9，请重新输入", "error");
                  zt = false;
                  return false;
                }
              }
            } else {
              if ($(this).val() == "") {
                $(this).val(0);
              }
              if (parseInt($('#from_' + selectid).find("#inspeed").val()) < -9 || parseInt($('#from_' + selectid).find("#inspeed").val()) > 9) {
                swal("OMG!", "gif速度范围在-9~9，请重新输入", "error");
                zt = false;
                return false;
              }
              //验证可以为负数、0、正数
              var regu = /^-?[1-9]+[0-9]*$|^0$/;
              if (!regu.test($(this).val())) {
                swal("OMA", "gif速度的格式不正确，请正确书写！", "error");
                $(this).val(0);
                return false;
              }
            }
          });
      
    $('#from_' + selectid).find("#staytime").blur(function () {
      if ($(this).val() == "") {

        $(this).val(1);
      }
    });
    $('#from_' + selectid).find("#width").blur(function () {
      if ($(this).val() == "") {
        $(this).val(0);
        $("#program_" + selectid).width(0);   
     }
    });

    $('#from_' + selectid).find("#high").blur(function () {
      if ($(this).val() == "") {

        $(this).val(0);
        $("#program_" + selectid).height(0);
      }
      
    });
    $('#from_' + selectid).find("#width").bind('input propertychange', function () {
      // if ($(this).val() == "") {

      //   $(this).val(0);
      // }
      var val = $(this).val().substr(0, 1);
      if (val == "0") {
        $(this).val(0);
      }
      var zoomsum = parseInt($("#zoomsum").text());
      if (parseInt($('#from_' + selectid).find("#width").val()) > parseInt($("#jwidth").val())) {

        $('#from_' + selectid).find("#left").val(0);
        $("#program_" + selectid).css("width", $("#jwidth").val());
        $('#from_' + selectid).find("#width").val($("#jwidth").val());

        if (zoomsum > 0) {
          zoomsum = zoomsum * 2;
          var w = parseInt($('#from_' + selectid).find("#width").val()) * parseInt(zoomsum);
          $("#program_" + selectid).css("width", w);
        }
        // $('#program_'+selectid).css("left",leftwz+"px");
        $('#program_' + selectid).css("left", $('#program_' + selectid).find("#leftdw").val() + "px");
         //画布
        textcanvas(selectid);
        onblurdiv();
        return;
      } else {
        var w = parseInt($('#from_' + selectid).find("#width").val())
        if (zoomsum > 0) {
          zoomsum = zoomsum * 2;
          w = parseInt($('#from_' + selectid).find("#width").val()) * parseInt(zoomsum);
        }
        $("#program_" + selectid).css("width", w);

        if ($("#program_" + selectid).find("img").val() == "") {

          // $("#program_"+selectid).find("img").css("width",parseInt($('#from_'+selectid).find("#width").val())-4);

        }

        if (parseInt($('#from_' + selectid).find("#width").val()) == parseInt($("#jwidth").val())) {


          //console.log(leftwz);

          $('#from_' + selectid).find("#left").val(0);


          // console.log($("#program").css("left"));

          //$('#program_'+selectid).css("left",leftwz+"px");
          $('#program_' + selectid).css("left", $('#program_' + selectid).find("#leftdw").val() + "px");




          // return;
        }
        console.log("宽：" + $('#from_' + selectid).find("#width").val());

        var left = parseInt($('#from_' + selectid).find("#left").val()) + parseInt($('#from_' + selectid).find("#width").val());
        if (left > $("#jwidth").val()) {
          //left=parent(left)-parseInt($("#jwidth").val());
          var reg = new RegExp("px", "g");

          //console.log(left);

          //left=parseInt($('#program_'+selectid).css("left").replace(reg, ""))-parseInt(left);


          left = parseInt($('#program_' + selectid).css("left").replace(reg, "")) - parseInt($('#from_' + selectid).find("#left").val());


          //console.log(left);
          $('#from_' + selectid).find("#left").val(0);
          $("#program_" + selectid).css("left", left + "px");

          //$('#from_'+selectid).find("#width").val( $("#jwidth").val());


          //$('#from_'+selectid).find("#width").val(parseInt($("#jwidth").val())-parseInt($('#from_'+selectid).find("#left").val()));
          //$("#program_"+selectid).css("width",parseInt($("#jwidth").val());
          //console.log(left);
        }
          //画布
       textcanvas(selectid);
      }
      //if(){
      // }
      onblurdiv();
     
    });
    $('#from_' + selectid).find("#high").bind('input propertychange', function () {
      // if ($(this).val() == "") {

      //   $(this).val(0);
      // }
      var val = $(this).val().substr(0, 1);
      if (val == "0") {
        $(this).val(0);
      }
      var zoomsum = parseInt($("#zoomsum").text());
      if (parseInt($('#from_' + selectid).find("#high").val()) > parseInt($("#jhigh").val())) {
        $("#program_" + selectid).css("height", $("#jhigh").val() + "px");
        $('#from_' + selectid).find("#high").val($("#jhigh").val());
        //if($("#program_"+selectid).find("img").val()==""){
        //$("#program_"+selectid).find("img").css("height",$("#jhigh").val()+"px");
        //$("#program_"+selectid).find("img").css("height",parseInt($("#jhigh").val())-4+"px");
        // console.log("ok");
        //$('#from_'+selectid).find("#top").val(0);
        //}


        if (zoomsum > 0) {
          zoomsum = zoomsum * 2;
          var h = parseInt($('#from_' + selectid).find("#high").val()) * parseInt(zoomsum);
          $("#program_" + selectid).css("height", h + "px");
        }

        $('#from_' + selectid).find("#top").val(0);
        $('#program_' + selectid).css("top", 0 + "px"); 
          //画布
         textcanvas(selectid);
        onblurdiv();
        return;
      }
      var h = parseInt($('#from_' + selectid).find("#high").val())
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        h = parseInt($('#from_' + selectid).find("#high").val()) * parseInt(zoomsum);
      }

      $("#program_" + selectid).css("height", h);


      //if($("#program_"+selectid).find("img").val()==""){

      //$("#program_"+selectid).find("img").css("height",parseInt($('#from_'+selectid).find("#high").val())-4);

      //}
      var top = parseInt($('#from_' + selectid).find("#top").val()) + parseInt($('#from_' + selectid).find("#high").val());
      console.log("高：" + $('#from_' + selectid).find("#high").val());
      //console.log(top);

      if (top > $("#jhigh").val()) {
        var reg = new RegExp("px", "g");
        top = parseInt($('#program_' + selectid).css("top").replace(reg, "")) - parseInt($('#from_' + selectid).find("#top").val())
        $("#program_" + selectid).css("top", top + "px");
        $('#from_' + selectid).find("#top").val(0);

      }

      if (parseInt($('#from_' + selectid).find("#high").val()) == parseInt($("#jhigh").val())) {


        //console.log(leftwz);

        $('#from_' + selectid).find("#top").val(0);


        // console.log($("#program").css("left"));

        $('#program_' + selectid).css("top", 0 + "px");



        // return;
      }
      //画布
   textcanvas(selectid);
      onblurdiv();
      // onblurdiv();
    });
    //节目信息分区 x y
    $('#from_' + selectid).find("#left").bind('input propertychange', function () {
      // if ($(this).val() == "") {

      //   $(this).val(0);
      // }
      if ($(this).val() < 0) {

        return;
      }
      var val = $(this).val().substr(0, 1);
      if (val == "0") {
        $(this).val(0);
      }
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var h = parseInt($(this).val()) * zoomsum;
        $("#program_" + selectid).css("left", h + "px");
      }
      if (zoomsum == 0) {
        $("#program_" + selectid).css("left", $(this).val() + "px");
      }

      Zonexy($("#program_" + selectid));


      var val = $(this).val().substr(0, 1);
      console.log(val);
      if (val == "0") {

        $(this).val(0);
      }
      return;

      var left = parseInt($("#jwidth").val()) - parseInt($('#from_' + selectid).find("#width").val());

      //var lefttow=parseInt(leftwz)+parseInt($('#from_'+selectid).find("#left").val());
      var lefttow = parseInt($('#program_' + selectid).find("#leftdw").val()) + parseInt($('#from_' + selectid).find("#left").val());


      if ($('#from_' + selectid).find("#left").val() > left) {

        $('#from_' + selectid).find("#left").val(left)
        // left=parseInt(leftwz)+parseInt(left);
        left = parseInt($('#program_' + selectid).find("#leftdw").val()) + parseInt(left);

        $("#program_" + selectid).css("left", left + "px");
        // $("#program_"+selectid).css("margin-left",left+"px");

        return;
      }

      $("#program_" + selectid).css("left", lefttow + "px");
      // $("#program_"+selectid).css("margin-left",$('#from_'+selectid).find("#left").val()+"px");
    //画布
    textcanvas(selectid);
    });
    $('#from_' + selectid).find("#top").bind('input propertychange', function () {
      // if ($(this).val() == "") {

      //   $(this).val(0);
      // }
      var val = $(this).val().substr(0, 1);
      if (val == "0") {
        $(this).val(0);
      }
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var h = parseInt($(this).val()) * zoomsum;
        $("#program_" + selectid).css("top", h + "px");
      }
      if (zoomsum == 0) {


        $("#program_" + selectid).css("top", $(this).val() + "px");
      }
      Zonexy($("#program_" + selectid));
      var val = $(this).val().substr(0, 1);
      console.log(val);
      if (val == "0") {

        $(this).val(0);
      }
       //画布
    textcanvas(selectid);
      return;

      // $("#program_"+selectid).css("margin-top",$('#from_'+selectid).find("#top").val()+"px");

    });
    //字体输入
    $('#from_' + selectid).find("textarea").bind('input propertychange', function () {
      $("#program_" + selectid).css("color", $('#from_' + selectid).find("#fontcolor").val()).css("font-size", $('#from_' + selectid).find("#fontsizeadd").find("option:selected").text()).css("overflow", "hidden");

      console.log($('#from_' + selectid).find("textarea").val());
      if ($('#from_' + selectid).find("#fontcolor").val() == "white" || $('#from_' + selectid).find("#fontcolor").val() == "yellow") {
        $('#from_' + selectid).find("textarea").css("color", "black");
      } else {
        $('#from_' + selectid).find("textarea").css("color", $('#from_' + selectid).find("#fontcolor").val());
      }

      $("#program_" + selectid).css("white-space", "pre-wrap").css("word-break", "break-all");
      $("#program_" + selectid).html("</div><input type='hidden' id='imgDataURL'><input type='hidden' id='leftdw' value=" + $("#program_" + selectid).find("#leftdw").val() + ">");
      $("#program_" + selectid).css("line-height", 1);


      var reg = new RegExp("px", "g");
      var size = $('#from_' + selectid).find("#fontsizeadd").find("option:selected").text().replace(reg, "");
      size = size.split("*")[0];
      $("#program_" + selectid).css("font-size", size + "px");
      if (zoomsum > 0) {
        var zoomsumval = zoomsum * 2;
        zoomsumval = size * zoomsumval;
        $("#program_" + selectid).css("font-size", zoomsumval + "px");
      }
       //画布
    textcanvas(selectid);
    });
    //炫彩效果
    $('#from_' + selectid).find("#Dazzle").click(function () {
      //  $('#myModalxc').modal();
      // alert(123);
      $("#selectxc").click();
      //  $('#myModalmb').modal('show');
    });
 //类型
 $('#from_' + selectid).find("#intype").change(function(){
  if ($("#from_" + selectid).find("#texttype").val() == "1") {
  Canvasfont(selectid);
  }

 });

    //字体
    $('#from_' + selectid).find("#typefaceval").change(function () {
      //  $('#myModalxc').modal();

      $("#program_" + selectid).find("div").css("font-family", $(this).val());
      $("#fosizeval").css("font-family", $(this).val());
      if ($(this).val() == "") {
        $("#program_" + selectid).css("display", "");
        $("#program_" + selectid).css("align-items", "");
        $("#from_" + selectid).find("#alignment").parent().hide();
        //  $("#from_"+selectid).find("#typefaceval").parent().css("margin-left","")

        $("#from_" + selectid).find("#randomFontColor").val("0");
        $("#from_" + selectid).find("#Dazzle,#randomFontColor").parent().hide();
      } else {
        // $("#from_" + selectid).find("#alignment").parent().show();
        // $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", "-24.8%");
        // $("#from_" + selectid).find("#Dazzle,#randomFontColor").parent().show();
        $("#from_" + selectid).find("#Dazzle").parent().show();
        //  $("#from_"+selectid).find("#typefaceval").parent().css("margin-left","-50%")

      }
      // if($(this).val()!=""){
      //   $('#from_' + selectid).find("#randomFontColor").val("0");
      // }
      //  $("#selectxc").click();
      //  $('#myModalmb').modal('show');
    });


     //计时类型选择
     $("#from_" + selectid).find("#reckonType").change(function () {



      var time = $("#from_" + selectid).find("#targetTime").val();
      var time = $("#from_" + selectid).find("#targetTime").val();
   
      var startTime = new Date().getTime();
      //结束时间
      var endTime = new Date(time);
      endTime = endTime.getTime();
      if($("#from_" + selectid).find("#reckonType").val()!="0" &&endTime<=startTime){
        $("#from_" + selectid).find('#editor input[name=dowNum]').attr("value", "-时间超时-");
        $("#from_" + selectid).find('#editor input[name=dowNum]').val("-时间超时-");
      }else{
      if (typeof ($("#from_" + selectid).find('#editor input[name=dowNum]').val()) != "undefined") {//(timeType,type,format,time)

        var timeval = writeCounDownDate(parseInt($(this).val()), $("#from_" + selectid).find(".timetext span").attr("val"), $("#from_" + selectid).find(".timetext span").text(), time, 1)
       
        $("#from_" + selectid).find('#editor input[name=dowNum]').attr("value", timeval);
        $("#from_" + selectid).find('#editor input[name=dowNum]').val(timeval);
      }
    }
      Canvasfont();

    });

    //目标时间改变
    $("#from_" + selectid).find("#targetTime").blur(function () {
      setTimeout(function(){
      //alert("就是店家啊开会"+ $("#from_" + selectid).find("#targetTime").val())
      var time = $("#from_" + selectid).find("#targetTime").val();
   
      var startTime = new Date().getTime();
      //结束时间
      var endTime = new Date(time);
      endTime = endTime.getTime();
      if($("#from_" + selectid).find("#reckonType").val()!="0" &&endTime<=startTime){
        $("#from_" + selectid).find('#editor input[name=dowNum]').attr("value", "-时间超时-");
        $("#from_" + selectid).find('#editor input[name=dowNum]').val("-时间超时-");
      }else{

     
      if (typeof ($("#from_" + selectid).find('#editor input[name=dowNum]').val()) != "undefined") {//(timeType,type,format,time)

        var timeval = writeCounDownDate(parseInt($("#from_" + selectid).find("#reckonType").val()), $("#from_" + selectid).find(".timetext span").attr("val"), $("#from_" + selectid).find(".timetext span").text(), time, 1)

        $("#from_" + selectid).find('#editor input[name=dowNum]').attr("value", timeval);
        $("#from_" + selectid).find('#editor input[name=dowNum]').val(timeval);
      }
    }
      Canvasfont();
  
    },800);
    });

    //对齐方式
    $('#from_' + selectid).find("#alignment").click(function () {

      if ($("#from_" + selectid).find("#alignment").val() == "0") {

        $("#program_" + selectid).css("display", "");
        $("#program_" + selectid).css("align-items", "");
      }
      if ($("#from_" + selectid).find("#alignment").val() == "2") {
        $("#program_" + selectid).css("display", "grid");
        $("#program_" + selectid).css("align-items", "flex-end");
      }
      if ($("#from_" + selectid).find("#alignment").val() == "1") {

        $("#program_" + selectid).css("display", "grid");
        $("#program_" + selectid).css("align-items", "center");

      }

    });
    $('#from_' + selectid).find("#randomFontColor").change(function () {

      if ($(this).val() != "0") {
        $('#from_' + selectid).find("#typefaceval").val("SimSun");
        $('#from_' + selectid).find("#Dazzle").parent().hide();
        $('#from_' + selectid).find("#alignment").parent().show();
        $('#from_' + selectid).find("#randomFontColor").parent().css("margin-left", "-24.8%");

      } else {
        $('#from_' + selectid).find("#randomFontColor").parent().css("margin-left", "");
        $('#from_' + selectid).find("#typefaceval").val("");
        $('#from_' + selectid).find("#alignment").parent().hide();
        $('#from_' + selectid).find("#Dazzle").parent().show();
        $('#from_' + selectid).find("#Dazzle").parent().css("margin-left", "");

      }

    });
    //字体颜色
    $('#from_' + selectid).find("#fontsizeadd").change(function () {
      //	$("#program_"+selectid).css("font-size",$(this).val()+"px")

      var reg = new RegExp("px", "g");
      var size = $(this).find("option:selected").text().replace(reg, "").split("*")[0];
      //$("#program_"+selectid).css("font-size",size[1]+"px");
      $("#program_" + selectid).css("font-size", size + "px");
      if (zoomsum > 0) {
        var zoomsumval = zoomsum * 2;
        zoomsumval = size * zoomsumval;
        $("#program_" + selectid).css("font-size", zoomsumval + "px");
      }
       //画布
    textcanvas(selectid);
    if($('#from_' + selectid).find("#type").val()=="3"){

      Canvasfont(); 

     }
    });
    //字体大小
    $('#from_' + selectid).find("#fontcolor").change(function () {
      $("#program_" + selectid).css("color", $(this).val());

      if ($(this).val() == "white" || $(this).val() == "yellow") {
        $('#from_' + selectid).find("textarea").css("color", "black");
      } else {
        $('#from_' + selectid).find("textarea").css("color", $(this).val());
      }
       //画布
    textcanvas(selectid);
      // $(this).css("background-color","#FFFFCC");
    });
    //背景颜色
    $('#from_' + selectid).find("#backcolor").change(function () {
      $("#program_" + selectid).css("background-color", $(this).val());
      // $(this).css("background-color","#FFFFCC");
    });
    //预览图片
    $('#from_' + selectid).find("#file1").change(function () {
      var file = this.files[0];
      // 确认选择的文件是图片                
      if (file.type.indexOf("image") == 0) {
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function (e) {
          // 图片base64化
          var newUrl = this.result;
          //	alert(newUrl);    
          $("#program_" + selectid).html("<img src='" + newUrl + "'  class='img-rounded' style=height:" + $("#from_" + selectid).find("#high").val() + "px;width:" + parseInt($("#from_" + selectid).find("#width").val() - 4) + "px;>" + "<input type='hidden' id='leftdw' value=" + $("#program_" + selectid).find("#leftdw").val() + ">");
          $.fn.jqLoading({ height: 100, width: 240, text: "图片上传中，请耐心等待...." });
          var formData = new FormData();
          formData.append('file', $('#from_' + selectid).find("#file1")[0].files[0]);
          $.ajax({
            url: domain.testUrl + "/Threeinjection/programManagement/FTPupload?coId=" + sessionStorage.getItem("coid"),
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false
          }).done(function (res) {

            $.fn.jqLoading("destroy");

            // logo=res;
            //res=logo;
            console.log(res);
            $('#from_' + selectid).find("#hfile1").val(JSON.parse(res).data)
          }).fail(function (res) {

          });
          //if(){
          // }
          //
          // preview.style.backgroundImage = 'url(' + newUrl + ')';
        };
      }
    });

    $('#from_' + selectid).find("#file2").change(function () {
      var file = this.files[0];
      // 确认选择的文件是图片                
      if (file.type.indexOf("image") == 0) {
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function (e) {
          // 图片base64化
          var newUrl = this.result;
          //	alert(newUrl);    
          //if(){
          //$("#program_"+selectid).html($('#from_'+selectid).find("textarea").val()+"<input type='hidden' id='leftdw' value="+$("#program_"+selectid).find("#leftdw").val()+">");


          $("#program_" + selectid).html("<img src='" + newUrl + "'  class='img-rounded' style=height:" + $("#from_" + selectid).find("#high").val() + "px;>" + "<input type='hidden' id='leftdw' value=" + $("#program_" + selectid).find("#leftdw").val() + ">");
          // }
          //
          // preview.style.backgroundImage = 'url(' + newUrl + ')';
          $.fn.jqLoading({ height: 100, width: 240, text: "图片上传中，请耐心等待...." });
          var formData = new FormData();
          formData.append('file', $('#from_' + selectid).find("#file2")[0].files[0]);
          $.ajax({
            url: domain.testUrl + "/Threeinjection/programManagement/FTPupload?coId=" + sessionStorage.getItem("coid"),
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false
          }).done(function (res) {
            // logo=res;
            //res=logo;
            $.fn.jqLoading("destroy");

            $('#from_' + selectid).find("#hfile2").val(JSON.parse(res).data)
          }).fail(function (res) {

          });

        };
      }
    });

    //向左移
    $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(0).on('click', function () {

      $('#from_' + selectid).find("#left").val(parseInt($("#program_" + selectid).css("left")) + 8);
      $("#program_" + selectid).css("left", $('#from_' + selectid).find("#left").val() + "px");
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var left = parseInt($("#program_" + selectid).css("left")) / zoomsum;
        if (left > 4) {
          $('#from_' + selectid).find("#left").val(parseInt(left));
        }
        //$('#from_'+selectid).find("#left").val(left);
        //  $("#program_"+selectid).css("left",left+"px");
      }
      Zonexy($("#program_" + selectid));
        //画布
        textcanvas(selectid);
      return;


    });
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(0).on('click', function () {

      var value = parseInt($('#from_' + selectid).find("#left").val()) - 8;
      if (value < 0) {
        $('#from_' + selectid).find("#left").val(parseInt(0)); $("#program_" + selectid).css("left", 0);
        return;
      }
      $('#from_' + selectid).find("#left").val(parseInt($("#program_" + selectid).css("left")) - 8);
      $("#program_" + selectid).css("left", $('#from_' + selectid).find("#left").val() + "px");
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var left = parseInt($("#program_" + selectid).css("left")) / zoomsum;
        $('#from_' + selectid).find("#left").val(parseInt(left));
      }
        //画布
        textcanvas(selectid);
      return;

    });


    //向上移

    $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(1).on('click', function () {

      $('#from_' + selectid).find("#top").val(parseInt($("#program_" + selectid).css("top")) + 8);
      $("#program_" + selectid).css("top", $('#from_' + selectid).find("#top").val() + "px");
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var top = parseInt($("#program_" + selectid).css("top")) / zoomsum;
        if (top > 4) {
          $('#from_' + selectid).find("#top").val(parseInt(top));
        }
      }
      Zonexy($("#program_" + selectid));
    
      return;



    });
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(1).on('click', function () {

      var value = parseInt($('#from_' + selectid).find("#top").val()) - 8;
      if (value < 0) {
        $('#from_' + selectid).find("#top").val(parseInt(0)); $("#program_" + selectid).css("top", 0);
        return;
      }
      $('#from_' + selectid).find("#top").val(parseInt($("#program_" + selectid).css("top")) - 8);
      $("#program_" + selectid).css("top", $('#from_' + selectid).find("#top").val() + "px");
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var top = parseInt($("#program_" + selectid).css("top")) / zoomsum;
        $('#from_' + selectid).find("#top").val(parseInt(top));
      }
       
      return;

    });






     //隐藏域宽和高
      $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(6).on('click', function () {

      $('#jwidth').val(parseInt($('#jwidth').val()) + 8);

      $("#program").css("width", $("#jwidth").val());
      //console.log($("#program div").css("left"));
      $("#program div").each(function () {
        var reg = new RegExp("px", "g");
        if (parseInt($("#jwidth").val()) < parseInt($(this).css("width"))) {
          $("#program").css("width", $(this).css("width"));
          $('#jwidth').val($(this).css("width").replace(reg, ""));
        }
      });

      setTimeout(function (i) {
        $("#program div").each(function (i) {
          var reg = new RegExp("px", "g");
          // console.log($("#program").css("margin-left"));
          //$(this).css("left",'');
          //$(this).find("#leftdw").val($(this).css("left").replace(reg, ""));
          //i=i+1;

          //$(".col-md-9").find(".form-inline").find("#left").val(0);

        }), 100
      });
     
        
    });
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(6).on('click', function () {
      //  $('.spinner input').val( parseInt($('.spinner input').val(), 10) - 8);  
      //$('#jwidth').val(parseInt($('#jwidth').val()) + 8);  


      var value = parseInt($('#jwidth').val()) - 8;

      if (value < 0) {

        return;
      }

      $('#jwidth').val(parseInt($('#jwidth').val()) - 8);

      $("#program").css("width", $("#jwidth").val());
      //console.log($("#program div").css("left"));
      $("#program div").each(function () {
        var reg = new RegExp("px", "g");
        if (parseInt($("#jwidth").val()) < parseInt($(this).css("width"))) {
          $("#program").css("width", $(this).css("width"));
          $('#jwidth').val($(this).css("width").replace(reg, ""));
        }
      });

      setTimeout(function (i) {
        $("#program div").each(function (i) {
          var reg = new RegExp("px", "g");
          // console.log($("#program").css("margin-left"));
          //$(this).css("left",'');
          // $(this).find("#leftdw").val($(this).css("left").replace(reg, ""));
          //i=i+1;
          //$(".col-md-9").find(".form-inline").find("#left").val(0);
        }), 100
      });
       
    });

      
      $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(7).on('click', function () {
      // return;
      
      $('#jhigh').val(parseInt($('#jhigh').val()) + 1);
      // if($("#jhigh").val()>190){
      // $("#jhigh").val(190);
      // $("#program").css("height",190);
      //return;
      //}else{
      $("#program").css("height", $("#jhigh").val());
       
      //$("#program").find("div").css("top","0px");
    });
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(7).on('click', function () {
      var value = parseInt($('#jhigh').val()) - 1;

      if (value < 0) {

        return;
      }
      $('#jhigh').val(parseInt($('#jhigh').val()) - 1);

      $("#program").css("height", $("#jhigh").val());
      // $("#program").find("div").css("top","0px");
      //}
      
    });


    //宽度
    $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(2).on('click', function () {
      
      var zoomsum = parseInt($("#zoomsum").text());
      if (parseInt($('#from_' + selectid).find("#width").val()) + 8 > parseInt($("#jwidth").val())) {

        if (zoomsum > 0) {
          zoomsum = zoomsum * 2;
          var w = parseInt(parseInt($("#jwidth").val())) * parseInt(zoomsum);
          $('#from_' + selectid).find("#width").val($("#jwidth").val());
          $("#program_" + selectid).css("width", w);

        } else {
          $('#from_' + selectid).find("#width").val($("#jwidth").val());
          $("#program_" + selectid).css("width", $("#jwidth").val());
        }
        //画布
      textcanvas(selectid);
        Zonexy($("#program_" + selectid));
        return;


      }

      $('#from_' + selectid).find("#width").val(parseInt($('#from_' + selectid).find("#width").val()) + 8);
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var w = parseInt($('#from_' + selectid).find("#width").val()) * parseInt(zoomsum);
        $("#program_" + selectid).css("width", w); Zonexy($("#program_" + selectid));
        //画布
      textcanvas(selectid);
        return;
      } else {
        $("#program_" + selectid).css("width", $('#from_' + selectid).find("#width").val());

        if ($("#program_" + selectid).find("img").val() == "") {

          //$("#program_"+selectid).find("img").css("width",parseInt($('#from_'+selectid).find("#width").val())-4);

        }

        if (parseInt($('#from_' + selectid).find("#width").val()) == parseInt($("#jwidth").val())) {


          //console.log(leftwz);

          //$('#from_'+selectid).find("#left").val(0);
          Zonexy($("#program_" + selectid));
 
          // console.log($("#program").css("left"));

          //$('#program_'+selectid).css("left",leftwz+"px");
          //  $('#program_'+selectid).css("left",$('#program_'+selectid).find("#leftdw").val()+"px");



          // return;
        }


        var left = parseInt($('#from_' + selectid).find("#left").val()) + parseInt($('#from_' + selectid).find("#width").val());
        if (left > $("#jwidth").val()) {
          //left=parent(left)-parseInt($("#jwidth").val());
          var reg = new RegExp("px", "g");

          //console.log(left);

          //left=parseInt($('#program_'+selectid).css("left").replace(reg, ""))-parseInt(left);


          left = parseInt($('#program_' + selectid).css("left").replace(reg, "")) - parseInt($('#from_' + selectid).find("#left").val());

          //$('#from_'+selectid).find("#left").val(0);
          //console.log(left);

          Zonexy($("#program_" + selectid));

        }
        //画布
      textcanvas(selectid);
      }

      
      onblurdiv();
    });
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(2).on('click', function () {
      var value = parseInt($('#from_' + selectid).find("#width").val()) - 8;
      if (value <= 0) {
        return;
      }
      $('#from_' + selectid).find("#width").val(parseInt($('#from_' + selectid).find("#width").val()) - 8);
      //console.log(123);

      //if(parseInt($('#from_'+selectid).find("#width").val())>parseInt($("#jwidth").val())){
      //$('#from_'+selectid).find("#left").val(0);
      var zoomsum = parseInt($("#zoomsum").text());
      $("#program_" + selectid).css("width", $("#jwidth").val());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var w = parseInt($('#from_' + selectid).find("#width").val()) * parseInt(zoomsum);

        //console.log(w);
        $("#program_" + selectid).css("width", w);
        //}
        //$('#from_'+selectid).find("#width").val($("#jwidth").val());
        //$('#program_'+selectid).css("left",$('#program_'+selectid).find("#leftdw").val()+"px");
        Zonexy($("#program_" + selectid));
        //return;
      } else {
        $("#program_" + selectid).css("width", $('#from_' + selectid).find("#width").val());

      }
      // Zonexy($("#program_"+selectid));
      onblurdiv();
        //画布
        textcanvas(selectid);
    });
    
    //进入速度
    $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(4).on('click', function () {
     
            var value = parseInt($('#from_' + selectid).find("#inspeed").val()) +1;
            if(sessionStorage.getItem("type")=="0"||sessionStorage.getItem("type")=="1"){
              if (value >50) {
                return;
              }
            }else{
              if (value >9) {
                return;
              }
            }
              
          
            $('#from_' + selectid).find("#inspeed").val(value);
  });
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(4).on('click', function () {

     
      var value = parseInt($('#from_' + selectid).find("#inspeed").val()) - 1;
     
      if ($('#from_' + selectid).find("#type").val()!= "2") {
        if (value <=0) {
          return;
        }
      }else{
          if (value <-9) {
            return;
          }
        }
      
      $('#from_' + selectid).find("#inspeed").val(parseInt($('#from_' + selectid).find("#inspeed").val()) - 1);

    });

    //停留时间
    $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(5).on('click', function () {
      $('#from_' + selectid).find("#staytime").val(parseInt($('#from_' + selectid).find("#staytime").val()) + 1);
    });
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(5).on('click', function () {

      var value = parseInt($('#from_' + selectid).find("#staytime").val()) - 1;

      if (value <= 0) {

        return;
      }


      $('#from_' + selectid).find("#staytime").val(parseInt($('#from_' + selectid).find("#staytime").val()) - 1);
    });


    //高度
    $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(3).on('click', function () {
     
      var zoomsum = parseInt($("#zoomsum").text());
      var jhigh = parseInt($('#from_' + selectid).find("#high").val()) + 8;
      $('#from_' + selectid).find("#high").val();
      if (jhigh > parseInt($("#jhigh").val())) {
        $('#from_' + selectid).find("#high").val($("#jhigh").val());
        jhigh = $("#jhigh").val();
        //$("#program_"+selectid).css("height",$("#jhigh").val());
        //$("#program_"+selectid).css("height",jhigh+"px");
        //$('#from_'+selectid).find("#high").val(jhigh);
        //if($("#program_"+selectid).find("img").val()==""){
        //$("#program_"+selectid).find("img").css("height",jhigh+"px");
      } $('#from_' + selectid).find("#high").val(jhigh);
      $('#program_' + selectid).css("top", 0 + "px");
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var w = parseInt($('#from_' + selectid).find("#high").val()) * parseInt(zoomsum);

        //console.log(w);
        $("#program_" + selectid).css("height", w);
      } else {

        $("#program_" + selectid).css("height", jhigh);
      }
      //}
      //$('#from_'+selectid).find("#width").val($("#jwidth").val());




  //画布
  textcanvas(selectid);

      return;
      //}
      $("#program_" + selectid).css("height", $('#from_' + selectid).find("#high").val());

      if ($("#program_" + selectid).find("img").val() == "") {

        $("#program_" + selectid).find("img").css("height", parseInt($('#from_' + selectid).find("#high").val()) - 4);

      }
      var top = parseInt($('#from_' + selectid).find("#top").val()) + parseInt($('#from_' + selectid).find("#high").val());

      //console.log(top);

      if (top > $("#jhigh").val()) {
        var reg = new RegExp("px", "g");
        top = parseInt($('#program_' + selectid).css("top").replace(reg, "")) - parseInt($('#from_' + selectid).find("#top").val())
        $("#program_" + selectid).css("top", top + "px");
        $('#from_' + selectid).find("#top").val(0);
      }

      if (parseInt($('#from_' + selectid).find("#high").val()) == parseInt($("#jhigh").val())) {


        //console.log(leftwz);

        $('#from_' + selectid).find("#top").val(0);


        // console.log($("#program").css("left"));

        $('#program_' + selectid).css("top", 0 + "px");



        // return;
      }

      onblurdiv();
        //画布
        textcanvas(selectid);
    });
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(3).on('click', function () {

      var value = parseInt($('#from_' + selectid).find("#high").val()) - 8;

      if (value <= 0) {

        return;
      }

  
      $('#from_' + selectid).find("#high").val(parseInt($('#from_' + selectid).find("#high").val()) - 8);

      var jhigh = parseInt($("#jhigh").val());
      // if($('#from_'+selectid).find("#high").val()>jhigh){
      //	$("#program_"+selectid).css("height",jhigh+"px");
      //	$('#from_'+selectid).find("#high").val(jhigh);

      // if($("#program_"+selectid).find("img").val()==""){


      // $("#program_"+selectid).find("img").css("height",jhigh+"px");


      //  }
      //$('#program_'+selectid).css("top",0+"px");

      var zoomsum = parseInt($("#zoomsum").text());
      //alert(zoomsum);
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var w = parseInt($('#from_' + selectid).find("#high").val()) * parseInt(zoomsum);

        //console.log(w);
        $("#program_" + selectid).css("height", w);
      }

      //return;
      // }

      if (zoomsum == 0) {
        $("#program_" + selectid).css("height", $('#from_' + selectid).find("#high").val());
      }
      //if($("#program_"+selectid).find("img").val()==""){

      // $("#program_"+selectid).find("img").css("height",parseInt($('#from_'+selectid).find("#high").val())-4);

      //  }
      var top = parseInt($('#from_' + selectid).find("#top").val()) + parseInt($('#from_' + selectid).find("#high").val());

      //console.log(top);

      if (top > $("#jhigh").val()) {
        var reg = new RegExp("px", "g");
        top = parseInt($('#program_' + selectid).css("top").replace(reg, "")) - parseInt($('#from_' + selectid).find("#top").val())
        $("#program_" + selectid).css("top", top + "px");
      }

      if (parseInt($('#from_' + selectid).find("#high").val()) == parseInt($("#jhigh").val())) {


        //console.log(leftwz);

        $('#from_' + selectid).find("#top").val(0);


        // console.log($("#program").css("left"));

        $('#program_' + selectid).css("top", 0 + "px");



        // return;
      }
      Zonexy($("#program_" + selectid));
      onblurdiv();
        //画布
        textcanvas(selectid);
    });

  }
  //显示日期插件
 // $('.date_picker').date_input();
 $("#starttime").click(function(){

    laydate({
      elem: '#starttime'
      
    });
  });
  
  $("#endtime").click(function(){
    laydate({
      elem: '#endtime'        
      });
});
 
   
  $("body").removeAttr("style");

  //$("body").css("overflow-x","hidden");

});
$(function () {
  //$("#programid").val();


  // alert(type);
  //return;


  //发送
  $("#sbfs").click(function () {
    var coidval = $("#companyid").val(); if (coidval.indexOf(',') != -1) {
      coidval = coidval.split(',')[0];
    }
    if ($("#device_id").val() == "" && coidval == "") {

      swal("OMG!", "请选择设备或单位", "error");
      return false;

    } else {
      var timer = setInterval(function ()   //开启循环：每秒出现一次提示框
      {
        $("body").mLoading("show");
      }, 500);
      $.ajax({
        type: 'POST',
        url: domain.testUrl + "/Threeinjection/programManagement/sendProgramInfoToDeivce",
        data: { sessionid: sessionStorage.getItem("sid"), "programid": sessionStorage.getItem("programid"), type: $("#type_val").val(), "devicenumber": $("#device_id").val(), companyid: coidval },
        sessionid: sessionStorage.getItem("sid"),

        success: function (response) {
          response = JSON.parse(response);
          if (response.code == "200") {


            clearInterval(timer);
            // $(".mloading-mask").hide();
            $("body").mLoading("hide");
            swal("success!", "节目提交成功，如需看到发送进度，请关注发送记录页面", "success");
            //  swal("success!", "发送成功", "success");
            $(".close").click();

          } else {
            clearInterval(timer);
            // $(".mloading-mask").hide();
            $("body").mLoading("hide");
            //  $(".mloading-mask").hide();
            swal("OMG!", "节目提交失败", "error");


          }
        }, error: function (response, ajaxOptions, thrownError) {
          clearInterval(timer);
          $(".mloading-mask").hide();
          swal("OMG!", "提交失败", "error");
        },
        complete: function (XMLHttpRequest, status) {

          if (status == 'timeout') {
            clearInterval(timer);
            $(".mloading-mask").hide();
            //    swal("OMG!", "发送失败", "error");

          }
        }
      });
    }
  });

});
//生成GUID的算法
window.uuid = function () {
  var s = [];
  var hexDigits = "0123456789abcdef";
  for (var i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
  s[8] = s[13] = s[18] = s[23] = "-";
  var uuid = s.join("");
  return uuid;
}

function getNowFormatDate(val) {
  var date = new Date();
  var seperator1 = "-";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  if(val==1){
    strDate = date.getDate()+1;
  }
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  var currentdate = year + seperator1 + month + seperator1 + strDate;
  return currentdate;
}

Date.prototype.Format = function (fmt) {
  //author:wangweizhen
  var o = {
    "M+": this.getMonth() + 1,                 //月份   
    "d+": this.getDate(),                    //日
    "h+": this.getHours(),                   //小时   
    "m+": this.getMinutes(),                 //分   
    "s+": this.getSeconds(),                 //秒   
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
    "S": this.getMilliseconds()             //毫秒   
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt))
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}

window.fontcolorval = function (val) {
  var fontcolor = "";
  switch (val) {

    case "0":
      fontcolor = "red";
      break;
    case "1":
      fontcolor = "green";
      break;
    case "2":
      fontcolor = "yellow";
      break;
    case "3":
      fontcolor = "blue";
      break;
    case "4":
      fontcolor = "purple";
      break;
    case "5":
      fontcolor = "cyan";
      break;
    case "6":
      fontcolor = "white";
      break;
  };
  return fontcolor;
}

window.fontcolorvaltow = function (val) {
  var fontcolor = "";
  switch (val) {
    case "0":
      fontcolor = "black";
      break;
    case "1":
      fontcolor = "red";
      break;
    case "2":
      fontcolor = "green";
      break;
    case "3":
      fontcolor = "yellow";
      break;
    case "4":
      fontcolor = "blue";
      break;
    case "5":
      fontcolor = "purple";
      break;
    case "6":
      fontcolor = "cyan";
      break;
    case "7":
      fontcolor = "white";
      break;
  };
  return fontcolor;
}

//读取图片分区
window.picture = function (response, i) {

  
  $("#program_" + selectid).css("width", response[0].children[i].width + "px");
  $("#program_" + selectid).css("height", response[0].children[i].high + "px");

  $("#program_" + selectid).css("top", response[0].children[i].top + "px");
  $("#program_" + selectid).css("left", response[0].children[i].lef + "px");
  //alert(response[0].children[i].children[0].text);
  $("#program_" + selectid).append(response[0].children[i].children[0].text);

  //$("#program_"+selectid).css("overflow","hidden").css("white-space","pre");

  //$("#program_"+selectid).css("left",response[0].children[i].lef+"px");

  var leftwz = $('#program_' + selectid).position().left + "px";

  var reg = new RegExp("px", "g");
  leftwz = leftwz.replace(reg, "");
  if (typeof (leftwz) != "undefined") {
    $('#program_' + selectid).find("#leftdw").val(leftwz);
  } else {

    $('#program_' + selectid).find("#leftdw").val(0);
  }






  //$("#program_"+selectid).css("font-size",response[0].children[i].children[0].fontsize+"px");

  //$("#program_"+selectid).css("font-size","16px");
  //alert(fontcolorvaltow(response[0].children[i].children[0].fontcolor));
  $("#program_" + selectid).css("color", fontcolorvaltow(response[0].children[i].children[0].fontcolor));




  $("#from_" + selectid).find("#left").val(response[0].children[i].lef);

  $("#from_" + selectid).find("#top").val(response[0].children[i].top);

  $("#from_" + selectid).find("#width").val(response[0].children[i].width);

  $("#from_" + selectid).find("#high").val(response[0].children[i].high);
  $("#from_" + selectid).find("#Dazzle").parent().hide();
  $("#from_" + selectid).find("#typefaceval").parent().hide();
  $("#from_" + selectid).find("#intype").val(response[0].children[i].children[0].intype == "0" ? 1 : response[0].children[i].children[0].intype);

  $("#from_" + selectid).find("#inspeed").val(response[0].children[i].children[0].inspeed);

  // $("#from_"+selectid).find("#fontcolor").val(fontcolorval(response[0].children[i].children[0].fontcolor));

  //$("#from_"+selectid).find("#fontsizeadd").val(response[0].children[i].children[0].fontsize);
  //console.log( $("#from_"+selectid).find("#fontsizeadd").find("option:selected").text());
  //var fontsize=$("#from_"+selectid).find("#fontsizeadd").find("option:selected").text().split("*");

  //$("#program_"+selectid).css("font-size", fontsize[1]+"px");



  $("#from_" + selectid).find("#backcolor").val(fontcolorvaltow(response[0].children[i].children[0].backcolor));

  //alert(response[0].children[i].children[0].fontsize);

  $("#from_" + selectid).find("#staytime").val(response[0].children[i].children[0].staytime);
  $("#from_" + selectid).find("#fosizeval").val(response[0].children[i].children[0].text);

  //alert(response[0].children[i].children[0].type);

  $("#from_" + selectid).find("#type").val(response[0].children[i].children[0].type);

  $("#from_" + selectid).find("#FTPurl").val(response[0].children[i].children[0].FTPurl);


  $("#from_" + selectid).find("#size").val(response[0].children[i].children[0].size);
  $("#from_" + selectid).find("#materialid").val(response[0].children[i].children[0].materialid);


  // alert(response[0].children[i].children.length);
  for (var j = 0; j < response[0].children[i].children.length; j++) {



    var imgval = domain.ipimg + response[0].children[i].children[j].path + "?ran=" + Math.random();


    $("#program_" + selectid).append("<img  id=imgadd_" + $("#from_" + selectid).find(".item").eq(j).find("#hfile1").val() + " src='" + imgval + "'  class='img-rounded' style=height:" + 100 + "%;width:" + 100 + "%;>");
    console.log("ss" + $("#program_" + selectid).html());
    $("#from_" + selectid).find(".item").eq(j).find('.preview').html("<img src='" + imgval + "' />");
    $("#from_" + selectid).find(".item").eq(j).find(".delete").show();

    $("#from_" + selectid).find(".item").eq(j).find('#pathimg').val((response[0].children[i].children[j].FTPurl));
    $("#from_" + selectid).find(".item").eq(j).find('#FTPurldele').val((response[0].children[i].children[j].FTPurl));
    $("#from_" + selectid).find(".item").eq(j).find('#pathsize').val(response[0].children[i].children[j].size);

    $("#from_" + selectid).find(".item").eq(j).find('#fileId').val(response[0].children[i].children[j].fileId);
    
    $("#from_" + selectid).find(".item").eq(j).find("#materialid").val(response[0].children[i].children[j].materialid);
    new ZResize({
      stage: "#program", //舞台 
      item: '#program_' + selectid, //可缩放的类名 
    });
  }
}
//读取动画分区
window.picturegif = function (response, i) {
  
 

  $("#program_" + selectid).css("width", response[0].children[i].width + "px");
  $("#program_" + selectid).css("height", response[0].children[i].high + "px");

  $("#program_" + selectid).css("top", response[0].children[i].top + "px");
  $("#program_" + selectid).css("left", response[0].children[i].lef + "px");
  //alert(response[0].children[i].children[0].text);
  $("#program_" + selectid).append(response[0].children[i].children[0].text);
  //$("#program_"+selectid).css("overflow","hidden").css("white-space","pre");

  $("#program_" + selectid).css("left", response[0].children[i].left + "px");

  var leftwz = $('#program_' + selectid).position().left + "px";

  var reg = new RegExp("px", "g");
  leftwz = leftwz.replace(reg, "");

  $('#program_' + selectid).find("#leftdw").val(leftwz);


  //$("#program_"+selectid).css("font-size",response[0].children[i].children[0].fontsize+"px");

  //$("#program_"+selectid).css("font-size","16px");
  //alert(fontcolorvaltow(response[0].children[i].children[0].fontcolor));
  $("#program_" + selectid).css("color", fontcolorvaltow(response[0].children[i].children[0].fontcolor));




  $("#from_" + selectid).find("#left").val(response[0].children[i].lef);

  $("#from_" + selectid).find("#top").val(response[0].children[i].top);

  $("#from_" + selectid).find("#width").val(response[0].children[i].width);

  $("#from_" + selectid).find("#high").val(response[0].children[i].high);

  $("#gifwidepth").val(response[0].children[i].width+"*"+response[0].children[i].high);


  $("#from_" + selectid).find("#intype").val(response[0].children[i].children[0].intype == "0" ? 1 : response[0].children[i].children[0].intype);

  $("#from_" + selectid).find("#inspeed").val(response[0].children[i].children[0].inspeed);

  $("#from_" + selectid).find("#fontcolor").val(fontcolorval(response[0].children[i].children[0].fontcolor));



  $("#from_" + selectid).find("#fontsizeadd").val(response[0].children[i].children[0].fontsize);

  $("#from_" + selectid).find("#backcolor").val(fontcolorvaltow(response[0].children[i].children[0].backcolor));
  $("#from_" + selectid).find("#Dazzle").parent().hide();
  $("#from_" + selectid).find("#typefaceval").parent().hide();
  //alert(response[0].children[i].children[0].fontsize);

  $("#from_" + selectid).find("#staytime").val(response[0].children[i].children[0].staytime);
  $("#from_" + selectid).find("#fosizeval").val(response[0].children[i].children[0].text);
  //alert(response[0].children[i].children[0].type);

  $("#from_" + selectid).find("#type").val(response[0].children[i].children[0].type);

  $("#from_" + selectid).find("#FTPurl").val(response[0].children[i].children[0].FTPurl);
  $("#from_" + selectid).find("#size").val(response[0].children[i].children[0].size);
  $("#from_" + selectid).find("#materialid").val(response[0].children[i].children[0].materialid);


  // alert(response[0].children[i].children.length);
  for (var j = 0; j < response[0].children[i].children.length; j++) {
    var jj = j + 5;

    $("#from_" + selectid).find(".item").eq(jj).find("#materialid").val(response[0].children[i].children[j].materialid);

    var gifValue = domain.ipimg + response[0].children[i].children[j].path + "?ran=" + Math.random();
   
    

    console.log("nn你" + domain.ipimg + response[0].children[i].children[j].path)
    
    // 创建对象,读取gif
    var img = new Image();
    // 改变图片的src
    img.src = gifValue;
    // 加载完成执行，不写加载，获取不到
   img.onload = function(){
     $("#gifwidepth").val(img.width + "*" + img.height);
      $("#program_" + selectid).append("<img  id=imgaddgif_" + $("#from_" + selectid).find(".item").eq(jj).find("#hfile2").val() + " src='" + gifValue + "'  class='img-rounded' >");
    };
    $("#from_" + selectid).find(".item").eq(jj).find('.preview').html('<img src="' + gifValue + "" + '" />');
    //gif尺寸小于分区
    gifwg(selectid);
   
    $("#from_" + selectid).find(".item").eq(jj).find(".delete").show();

    $("#from_" + selectid).find(".item").eq(jj).find('#pathimggif').val(response[0].children[i].children[j].FTPurl);
    $("#from_" + selectid).find(".item").eq(jj).find('#FTPurlgif').val(response[0].children[i].children[j].FTPurl);
    $("#from_" + selectid).find(".item").eq(jj).find('#pathgifsize').val(response[0].children[i].children[j].size);

    // $("#from_" + selectid).find(".item").eq(jj).find('#giftime').val(response[0].children[i].children[j].gifPlayTime);

    

    $("#from_" + selectid).find(".item").eq(jj).find('#fileId').val(response[0].children[i].children[j].fileId);
  }

}
//删除这个方法
window.onblurdiv = function () {
  //console.log("f分区信息"+$("#material #"+selectid + " a").text().trim())
  //  console.log("");
  return;
  if ($("#from_" + selectid).find("#texttype").val() == "0") {

   
    return false;

  }

  // 电脑字体
  if ($("#program .transparent_class").length > 0) {



    $('#splitscreen').animate({ 'scrollTop': 0 }, 0);
    var idonblur = $("#material li[style]").attr("id");
    //var html=UE.getEditor("container"+selectid).getContent();

   


    //if(){
    //texttype
    // }

    $("#program_" + idonblur).html("<input type='hidden' id='imgDataURL'><input type='hidden' id='leftdw' value=" + $("#program_" + idonblur).find("#leftdw").val() + ">");
    $("#program_" + idonblur).find("p:eq(0)").css("line-height", "1");
    //$("#program_"+idonblur).css("white-space","pre").css("overflow","hidden");
    //chen,预览
    $("#program_" + idonblur).css("word-wrap", "break-word").css("word-break", "break-all");
    //var content = document.getElementById("program_"+selectid);
    //   $.fn.jqLoading({ height: 100, width: 240, text: "正在生成图片...." }); 
    $("#_" + selectid).remove();
    $("body").append("<div id=_" + selectid + " style='width:" + $("#program_" + selectid).outerWidth() + "px;height:auto'>" + $("#program_" + selectid).html() + "<div>");
    $("#_" + selectid).css("word-wrap", "break-word").css("word-break", "break-all").css("border", "2px dashed rgb(255, 255, 255)");
    //.css("line-height",0.96);
    $("#_" + selectid).hide();


    $("#program_" + selectid).find(".resize-panel").remove();
    //console.log($("#_"+$("#material li").eq(basesum).attr("id")).outerHeight());
    var w = $("#program_" + selectid).outerHeight();
    if (parseInt($("#_" + selectid).outerHeight()) > parseInt(w)) {

      //$("#program_"+selectid).css("height",$("#_"+selectid).outerHeight()+"px");
    }
    //$(".transparent_class").each(function(i){
    //new ZResize({ 
    //stage: "#program", //舞台 
    //item: $(this), //可缩放的类名 
    //});
    //});
    //字体放大
    // Fontmax();
 
    //x,y w,h输入框重新赋值
    if ($("#material #"+selectid).length>0){
    if ($("#material #"+selectid+ " a").text().trim() == "文本"){
      if($("#from_" + selectid).find("#texttype").val() == 1){
           Canvasfont();
      }
    }
  }
}
}
//x,y w,h输入框重新赋值
function xywhinputval() {
  $(".transparent_class").each(function (i) {
    var id = $(this).attr("id");
    var reg = new RegExp("px", "g");
    id = id.split("_")[1];
    var zoomsum = $("#zoomsum").text();

    if (zoomsum != "0") {
      var sumpx = parseInt(zoomsum) * 2;

      var left = $(this).css("left").replace(reg, "");
      var top = $(this).css("top").replace(reg, "");


      if (left == "auto") {
        left = 0;
      }

      if (top == "auto") {
        top = 0;
      }


      left = parseInt(left) / sumpx;
      top = parseInt(top) / sumpx;
      if (left == "NaN") {

        left = 0;
      }
      if (top == "NaN") {

        top = 0;
      }
      //  alert(left);
      $("#from_" + id).find("#left").val(parseInt(left));
      $("#from_" + id).find("#top").val(parseInt(top));
      // console.log($(this).outerWidth());
      var w = parseInt($(this).outerWidth()) / sumpx;
      var h = parseInt($(this).outerHeight()) / sumpx;
      $("#from_" + id).find("#high").val(parseInt(h));
      $("#from_" + id).find("#width").val(parseInt(w));
      //div1Height =parseInt(div1.height()),  
      // div2Height =parseInt(div2.outerHeight()),  
      // var left=$("") 
    } else {
      var left = $(this).css("left").replace(reg, "");
      var top = $(this).css("top").replace(reg, "");
      if (left == "auto") {
        left = 0;
      }

      if (top == "auto") {
        top = 0;
      }
      $("#from_" + id).find("#left").val(parseInt(left));
      $("#from_" + id).find("#top").val(parseInt(top));
      var w = parseInt($(this).outerWidth());
      var h = parseInt($(this).outerHeight());
      $("#from_" + id).find("#high").val(parseInt(h));
      $("#from_" + id).find("#width").val(parseInt(w));
    }

  });
}
//分区是否重叠
function overlapdiv(obj1, obj2) {
  var obj1top = parseInt($(obj1).css("top"));
  var obj1left = parseInt($(obj1).css("left"));
  var obj1width = parseInt($(obj1).width());
  var obj1height = parseInt($(obj1).height());
  var obj2top = parseInt($(obj2).css("top"));
  var obj2left = parseInt($(obj2).css("left"));
  var obj2width = parseInt($(obj2).width());
  var obj2height = parseInt($(obj2).height());

 //iE浏览器下
 if(isNaN(obj1left)){ 
  obj1top = parseInt($(obj1).position().top);
  obj1left = parseInt($(obj1).position().left);
  obj2top = parseInt($(obj2).position().top);
  obj2left = parseInt($(obj2).position().left);
 }

  if ((obj2top + obj2height < obj1top) || (obj2top > obj1top + obj1height) || (obj2left + obj2width < obj1left) || (obj2left > obj1left + obj1width)) {
    // console.log(123);
    return false;
  }
  else {
    console.log(456);
    return true;
  }

}
//分区重叠提醒
window.overlap = function () {
  $("#error").html("");
  if ($("#material li").length > 1) {
    var overlapvalue=true;
    var sum = $(".transparent_class").length - 1;
    $(".transparent_class").each(function (i) {

      var ii = i;  overlapvalue = true;
      if ($(".transparent_class").length > 1) {
        $(".transparent_class").each(function (i) {
          $(".transparent_class").eq(ii).css("border", "2px dashed rgb(255, 255, 255)");
          if (ii != i) {
            if (overlapdiv($(".transparent_class").eq(ii), $(".transparent_class").eq(i))) {
              $(".transparent_class").eq(i).css("border", "2px dashed red");
              $("#error").html("分区不能重叠");
              overlapvalue = false;
              return false;
            }
          }
        });
      } else if ($(".transparent_class").length == 1) {
        $(".transparent_class").eq(ii).css("border", "rgb(255, 255, 255)");
        if (overlapdiv($(".transparent_class").eq(ii), $(".transparent_class").eq(1))) {
          $(".transparent_class").eq(ii).css("border", "2px dashed red");
          overlapvalue = false;
          $("#error").html("分区不能重叠");
          return false;

        }
      }
      if (!overlapvalue) {
        //swal("OMG!", "分区不能重叠", "error");
        return false;
      }
    });
  }
  if (!overlapvalue) {
    return;
  }
}
//字体放大,换了一种显示，不用div显示预览，用不到
// function Fontmax() {
//   //遍历所有分区
//   $(".transparent_class").each(function (i) {
//     var id = $(this).attr("id");

//     id = id.split("_")[1];
//     if ($('#from_' + id).find("#texttype").val() == 1) {
//       var html = UE.getEditor("container" + id).getContent();
//       //chen改
//       // html = "<div  style='width:inherit;font-family:monospace'>" + html + "</div>";
//       $("#program_" + id).html("<input type='hidden' id='imgDataURL'><input type='hidden' id='leftdw' value=" + $("#program_" + id).find("#leftdw").val() + ">");
//       $("#program_" + id).find("p:eq(0)").css("line-height", "1");
//       //chen,预览
//       $("#program_" + id).css("word-wrap", "break-word").css("word-break", "break-all");
//       $("#program_" + id).css("font-size", '');
//       //复制隐藏div
//       $("#_" + id).remove();
//       $("body").append("<div id=_" + id + " style='width:" + $("#program_" + id).outerWidth() + "px;height:auto'>" + $("#program_" + id).html() + "<div>");
//       $("#_" + selectid).css("word-wrap", "break-word").css("word-break", "break-all").css("border", "2px dashed rgb(255, 255, 255)");
//       $("#_" + id).hide();

//       //字体放大
//       if (zoomsum > 0) {
//         $("#program_" + id + " div").find("p").each(function (i) {
//           console.log(i);
//           spanan(this);
//         });
//       }
//     } else {

//       $("#program_" + id).css("color", $("#from_" + id).find("#fontcolor").val());

//     }

//     new ZResize({
//       stage: "#program", //舞台 
//       item: $(this), //可缩放的类名 
//     });

//   });
// }
window.spanan = function (thi) {
  var reg = new RegExp("px", "g");
  $(thi).children("span").each(function () {
    var px = $(this).css("font-size");
    px = px.replace(reg, "");
    var sumpx = zoomsum * 2;
    px = px * sumpx;
    $(this).css("font-size", px + "px");
    $(this).children("span").each(function (i) {
      var px = $(this).css("font-size");
      px = px.replace(reg, "");
      var sumpx = zoomsum * 2;
      px = px * sumpx;
      $(this).css("font-size", px + "px");
      spanan(this);
    });
  });
}


//字体缩小
function Fontmin(thi) {
  //遍历所有分区
  $(thi).each(function (i) {
    var id = $(thi).attr("id");
    id = id.split("_")[1];
    if ($('#from_' + id).find("#texttype").val() == 1) {

      //字体缩小
      if (zoomsum > 0) {
        $("#program_" + id + " div").find("p").each(function (i) {
          //console.log(i);
          spananmin(this);
        });
      }
    } new ZResize({
      stage: "#program", //舞台 
      item: $(this), //可缩放的类名 
    });
  });
}
//缩小放大修改文字大小
window.spananmin = function (thi, sta) {
  var reg = new RegExp("px", "g");
  $(thi).children("span").each(function () {
    var px = $(this).css("font-size");
    px = px.replace(reg, "");
    var sumpx = zoomsum * 2;
    if (sta == "0") {
      px = px / sumpx;
    } else {
      px = px * sumpx;
    }
    $(this).css("font-size", px + "px");
    $(this).children("span").each(function (i) {
      var px = $(this).css("font-size");
      px = px.replace(reg, "");
      var sumpx = zoomsum * 2;
      if (sta == "0") {
        px = px / sumpx;
      } else {
        px = px * sumpx;
      }
      $(this).css("font-size", px + "px");
      spananmin(this, sta);
    });
  });
}
//还原分区大小
window.Restorefq = function (thi, sta) {
  if (zoomsum > 0) {
    var sumpx = zoomsum * 2;
    //遍历所有分区
    $(thi).each(function (i) {
      var w = parseInt($(thi).eq(i).css("width"));
      if (sta == 0) {
        $(thi).eq(i).css("width", parseInt($(thi).eq(i).css("width")) / sumpx);
        $(thi).eq(i).css("height", parseInt($(thi).eq(i).css("height")) / sumpx);
      } else {
        $(thi).eq(i).css("width", parseInt($(thi).eq(i).css("width")) * sumpx);
        var h = parseInt($(thi).eq(i).css("height")) * sumpx;
        //alert(h);
        $(thi).eq(i).css("height", h + "px");
      }
      //x和y轴移动
      if (parseInt($(thi).eq(i).css("left")) > 0) {
        if (sta == 0) {
          var left = parseInt($(thi).eq(i).css("left")) / sumpx;
          $(thi).eq(i).css("left", left);
        } else {
          var left = parseInt($(thi).eq(i).css("left")) * sumpx;
          $(thi).eq(i).css("left", left);
        }
      }
      if (parseInt($(thi).eq(i).css("top")) > 0) {
        if (sta == 0) {
          var top = parseInt($(thi).eq(i).css("top")) / sumpx;
          $(thi).eq(i).css("top", top);
        } else {
          var top = parseInt($(thi).eq(i).css("top")) * sumpx;
          $(thi).eq(i).css("top", top);
        }
      }
      var id = $(thi).attr("id").split("_")[1];
      if (zoomsum > 0) {
        $("#_" + id).css("width", parseInt(w) / sumpx);
      } else {
        $("#_" + id).css("width", parseInt(w) * sumpx);
      }
      if ($("#from_" + id).find("#type").val() == "0") {
        if ($('#from_' + id).find("#texttype").val() == 0) {
          var reg = new RegExp("px", "g");
          var size = $('#from_' + id).find("#fontsizeadd").find("option:selected").text().replace(reg, "");
          size = size.split("*")[0];
          $("#program_" + id).css("font-size", size + "px");
          if (zoomsum > 0) {
            var zoomsumval = 0;
            if (sta == 0) {
              zoomsumval = size / sumpx;
            } else {

              zoomsumval = size * sumpx;
            }
            $("#program_" + id).css("font-size", zoomsumval + "px");
            //$("#_"+id).css("",);
          }
        } else {
          // alert(123);
          $(thi).find("p").each(function (i) {
            spananmin(this, sta);
          });
        }
        $("#_" + id).html($(thi).html());
        $("#_" + id).css("border", "2px dashed rgb(255, 255, 255)");
      }
    });
  }
};
//分区位置是否超出
window.Zonexy = function (div2, pd) {

  //console.log("test");
  try {
    var div1 = $("#program");
    var div1Width = parseInt(div1.width()),
      //console.log(div1Width);
      div2Width = parseInt(div2.outerWidth()),
      div1Height = parseInt(div1.height()),
      div2Height = parseInt(div2.outerHeight()),
      div1Left = parseInt($(div1).css("left")),
      div2Left = parseInt($(div2).css("left")),
      div1Top = parseInt($(div1).css("top")),
      div2Top = parseInt($(div2).css("top")),
      div1Right = div1Left + div1Width,
      div2Right = div2Left + div2Width,
      div1Bottom = div1Top + div1Height,
      div2Bottom = div2Top + div2Height;
     //iE浏览器下
    if(isNaN(div1Left)){ 
      div1Left=parseInt($(div1).position().left);
      div2Left = parseInt($(div2).position().left),
      div1Top= parseInt($(div1).position().top),
      div2Top= parseInt($(div2).position().top),
      div1Right = div1Left + div1Width,
      div2Right = div2Left + div2Width,
      div1Bottom = div1Top + div1Height,
      div2Bottom = div2Top + div2Height;
    }
    //console.log("zo:"+div2Right);
    if (div2Left < div1Left) {
      console.log("左边超出");
      // div2.css("left","10px");  
      $(div2).css("left", 0 + "px");
      //$(div2).css("width",$("#program").width()+"px");
      //  $(div2).find("#height").val($("#program").height());
    }
    if (div2Top < div1Top) {
      console.log("上边超出");
      //  div2.css("top","10px");  
      $(div2).css("top", 0 + "px");

      // $(div2).css("height",$("#program").height()+"px");
    } else {
      if (pd == 1) {
        var zoomsum = parseInt($("#zoomsum").text());
        if (zoomsum > 0) {
          zoomsum = zoomsum * 2;
          var maxtop = parseInt($("#program").height()) - (parseInt($("#from_" + selectid).find("#high").val()) * zoomsum);

          var topmax = parseInt($("#program_" + selectid).css("top")) + parseInt($("#program_" + selectid).outerHeight());


          if (parseInt(topmax) > parseInt($("#program").height())) {

            $(div2).css("top", maxtop + "px");
          }

        } else {
          var maxtop = parseInt($("#program").height()) - parseInt($("#from_" + selectid).find("#high").val());

          var topmax = parseInt($("#program_" + selectid).css("top")) + parseInt($("#program_" + selectid).outerHeight());


          if (parseInt(topmax) > parseInt($("#program").height())) {

            $(div2).css("top", maxtop + "px");
          }
          console.log("进去");
        }
      }
    }
    if (div2Right > div1Right) {

      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var w1 = parseInt($("#program").width());
        var w2 = parseInt($("#from_" + selectid).find("#width").val()) * zoomsum;

        if (pd == 1) {//碰撞计算
          var maxleft = parseInt(w1) - parseInt(w2);
          console.log("右边超出:" + maxleft);

          $(div2).css("left", maxleft + "px");
          $("#from_" + selectid).find("#left").val(maxleft/2);
          $(div2).css("width", w2 + "px");
          return false;
          //  return false;
          //if(w1==w2||maxleft<8){
          //$(div2).css("left",0+"px"); $("#from_"+selectid).find("#left").val(0);
          //}
        }
        if (parseInt($("#from_" + selectid).find("#left").val()) >= parseInt(sessionStorage.getItem("width"))) {
          var val1 = parseInt(sessionStorage.getItem("width")) - 4;
          $("#from_" + selectid).find("#left").val(4);
          $("#from_" + selectid).find("#width").val(val1);
          $("#program_" + selectid).css("left", "8px");
          $("#program_" + selectid).css("width", (val1 * zoomsum) + "px");
          return false;
        } else {
          console.log("w:" + $("#from_" + selectid).find("#width").val());
          var val1 = parseInt(sessionStorage.getItem("width")) - parseInt($("#from_" + selectid).find("#left").val());

          $("#from_" + selectid).find("#width").val(val1);
          $("#program_" + selectid).css("width", (val1 * zoomsum) + "px");
        }


      } else {
        if (pd == 1) {//碰撞计算
          var maxleft = parseInt($("#program").width()) - parseInt($("#from_" + selectid).find("#width").val());
          $(div2).css("left", maxleft + "px");
          $("#from_" + selectid).find("#left").val(maxleft);
          $(div2).css("width", $("#from_" + selectid).find("#width").val() + "px");
          return false;
        }
        //console.log(123);
        var maxleft = parseInt($("#program").width()) - parseInt($("#from_" + selectid).find("#width").val());
        console.log("右边超出:" + maxleft);
        console.log($("#from_" + selectid).find("#left").val());
        if (parseInt($("#from_" + selectid).find("#left").val()) >= parseInt(sessionStorage.getItem("width"))) {
          var val1 = parseInt(sessionStorage.getItem("width")) - 4;
          $("#from_" + selectid).find("#left").val(4);
          $("#from_" + selectid).find("#width").val(val1);
          $("#program_" + selectid).css("left", "4px");
          $("#program_" + selectid).css("width", val1 + "px");
          console.log("qwwq");
          return false;
        } else {
          console.log("qwwq1");
          console.log("w:" + $("#from_" + selectid).find("#width").val());

          var val1 = parseInt(sessionStorage.getItem("width")) - parseInt($("#from_" + selectid).find("#left").val());

          $("#from_" + selectid).find("#width").val(val1);

          $("#program_" + selectid).css("width", val1);
          // $(div2).css("left", maxleft + "px");
          // $("#from_" + selectid).find("#left").val(maxleft);
          // $(div2).css("width", $("#from_" + selectid).find("#width").val() + "px");

        }
        // return false;
        //if(parseInt($("#program").width())==parseInt($("#from_"+selectid).find("#width").val())||maxleft<8){
        //$(div2).css("left",0+"px"); 
        //$("#from_"+selectid).find("#left").val(0);
        //}

      }
    } else {

      var zoomsum = parseInt($("#zoomsum").text());
      console.log("上边超出" + div2Top);
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var lef = parseInt($(div2).css("left")) / zoomsum;

        // console.log(lef);
       // $("#from_" + selectid).find("#left").val(parseInt(lef));
       if(isNaN(lef)){ 
        $("#from_" + selectid).find("#left").val(parseInt(0));
      }else{

        $("#from_" + selectid).find("#left").val(parseInt(lef));
      }


      } else {

        $("#from_" + selectid).find("#left").val(parseInt($(div2).css("left")));
      }
    }
    if (div2Bottom > div1Bottom) {
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var h1 = parseInt($("#program").height());
        var h2 = parseInt($("#from_" + selectid).find("#high").val()) * parseInt(zoomsum);

        if (pd == 1) {
          var maxtop = parseInt(h1) - parseInt(h2);
          console.log("1下边超出:" + maxtop);
          $(div2).css("top", maxtop + "px");
          $("#from_" + selectid).find("#top").val(maxtop);
          $(div2).css("height", h2 + "px");
          return false;
        }

        if (parseInt($("#from_" + selectid).find("#top").val()) >= parseInt(sessionStorage.getItem("high"))) {
          var val1 = parseInt(sessionStorage.getItem("high")) - 4;
          $("#from_" + selectid).find("#top").val(4);
          $("#from_" + selectid).find("#high").val(val1);
          $("#program_" + selectid).css("top", "8px");
          $("#program_" + selectid).css("height", (val1 * zoomsum) + "px");
          console.log("2下边超出:" + val1);
          return false;
        } else {

          console.log("w:" + $("#from_" + selectid).find("#high").val());
          var val1 = parseInt(sessionStorage.getItem("high")) - parseInt($("#from_" + selectid).find("#top").val());

          $("#from_" + selectid).find("#high").val(val1);

          $("#program_" + selectid).css("height", (val1 * zoomsum) + "px");
        }
      } else {

        if (pd == 1) {
          var maxtop = parseInt($("#program").height()) - parseInt($("#from_" + selectid).find("#high").val());
          console.log("1下边超出:" + maxtop);
          $(div2).css("top", maxtop + "px");
          $("#from_" + selectid).find("#top").val(maxtop);
          $(div2).css("height", $("#from_" + selectid).find("#high").val() + "px");
          return false;
        }
        var maxtop = parseInt($("#program").height()) - parseInt($("#from_" + selectid).find("#high").val());
        if (parseInt($("#from_" + selectid).find("#top").val()) >= parseInt(sessionStorage.getItem("high"))) {
          console.log("2下边超出:" + maxtop);
          var val1 = parseInt(sessionStorage.getItem("high")) - 4;
          $("#from_" + selectid).find("#top").val(4);
          $("#from_" + selectid).find("#high").val(val1);
          $("#program_" + selectid).css("top", "4px");
          $("#program_" + selectid).css("height", val1 + "px");
          return false;
        } else {

          console.log("w:" + $("#from_" + selectid).find("#high").val());
          var val1 = parseInt(sessionStorage.getItem("high")) - parseInt($("#from_" + selectid).find("#top").val());

          $("#from_" + selectid).find("#high").val(val1);

          $("#program_" + selectid).css("height", val1);
        }

      }
    } else {
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var top = parseInt($(div2).css("top")) / zoomsum;
      //  $("#from_" + selectid).find("#top").val(parseInt(top));
      if(isNaN(top)){ 
        $("#from_" + selectid).find("#top").val(parseInt(0));
      }else{

        $("#from_" + selectid).find("#top").val(parseInt(top));
      }

      } else {
        //var top=parseInt($(div2).css("top"));

        $("#from_" + selectid).find("#top").val(parseInt($(div2).css("top")));

        // $("#from_"+selectid).find("#top").val(parseInt(top));
      }
    }
    //$("#from_"+selectid).find("#left").val(div2Left);
    //$("#from_"+selectid).find("#top").val(div2Top);
    //console.log("qq");
  //  xywhinputval();
  } catch (ex) {
    console.log("zo:" + ex);
  }
  //画布
  //textcanvas(selectid,pd);
   setTimeout(function(){
 textcanvas(selectid, pd);
 },200);
  if(pd==1)
  gifwg(selectid);
  overlap();//分区重叠
}
//炫彩效果弹框
window.xc = function (val) {

  if (val == 0) {
    $("#from_" + selectid).find("#Dazzle").html("<option value='0'>无效果</option>");
    $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", " ");
    $("#from_" + selectid).find("#fontcolor").parent().show();
    //  $("#from_" + selectid).find("#typefaceval").parent().show();
    $("#from_" + selectid).find("#alignment").parent().hide();
    // $("#from_" + selectid).find("#typefaceval").val("");
    $("#from_" + selectid).find("#alignment").val("0");
    $("#program_" + selectid).find("div").css("font-family", "");
    $("#program_" + selectid).css("display", "");
    $("#program_" + selectid).css("align-items", "");
    // $("#from_" + selectid).find("#typefaceval").parent().css("margin-left", "")
    // $("#from_" + selectid).find("#randomFontColor").parent().show();

  } else {
    $("#from_" + selectid).find("#Dazzle").html("<option value='" + val + "'>炫彩效果" + val + "</option>");
    $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", "");
    $("#from_" + selectid).find("#typefaceval").val("4");
    $("#from_" + selectid).find("#alignment").val("0");
    //隐藏颜色
    $("#from_" + selectid).find("#fontcolor").parent().hide();
    //  $("#from_" + selectid).find("#typefaceval").parent().hide();
    $("#from_" + selectid).find("#alignment").parent().hide();
    $("#program_" + selectid).find("div").css("font-family", "");
    $("#program_" + selectid).css("display", "");
    $("#program_" + selectid).css("align-items", "");
    $("#from_" + selectid).find("#randomFontColor").val("0");
    $("#from_" + selectid).find("#randomFontColor").parent().hide();
  }
  $(".close").click();
}


//gif尺寸小于分区
window.gifwg=function(index){
  if ($("#material #"+index + " a").text().trim() == "动画") {
    var  gifwidepth=$("#gifwidepth").val().split('*'),width=0,height=0;
    width=zoomsum==0?parseInt(gifwidepth[0]):(parseInt(gifwidepth[0]) * (zoomsum*2));
    height=zoomsum==0?parseInt(gifwidepth[1]):(parseInt(gifwidepth[1]) * (zoomsum*2));
    $("#program_"+index).find("img").width(width);
    $("#program_"+index).find("img").height(height);
    $("#program_"+index).find("img").css({"position":"absolute","margin":"auto","top":"0",
                                          "right":"0","bottom":"0","left":"0","z-index":"1"});
  }
}


//时段个数选择
window.timeChange = function () {
  for (var i = 1; i <= 8; i++) {
    //先全部禁用
    $("#liveStart" + i).find("input").attr("disabled", true);
    $("#liveStart" + i).css("color", "gainsboro");
    $("#liveEnd" + i).find("input").attr("disabled", true);
    $("#liveEnd" + i).css("color", "gainsboro");
  }
  for (var i = 1; i <= parseInt($("#liveCount").val()); i++) {
    //根据选择个数来设置

    $("#liveStart" + i).find("input").removeAttr("disabled");
    $("#liveStart" + i).css("color", "");
    $("#liveEnd" + i).find("input").removeAttr("disabled");
    $("#liveEnd" + i).css("color", "");

  }
}



//变量
window.textcanvas = function (index, pd) {

  if ($("#material #" + index + " a").text().trim() == "文本" ||$("#material #" + index + " a").text().trim() == "时间" ||$("#material #" + index + " a").text().trim() == "计时") {
    //每次进来都清掉，再重新画上去
    var textcanvas = "<canvas id=textcanvas width=" + (parseInt($("#program_" + index).outerWidth())) + " height=" + $("#program_" + index).outerHeight() + " class=textcanvas></canvas>";
    console.log("pid进来"+$("#program_" + index).find("#textcanvas")[0])
    if (pd != 1) {
      $("#program_" + index).html(textcanvas);
    }
  
    var mycanvas = $("#program_" + index).find("#textcanvas")[0];
    var context = mycanvas.getContext("2d");
    mycanvas.width =parseInt($("#program_" + index).outerWidth());
    mycanvas.height =parseInt($("#program_" + index).outerHeight());
    context.clearRect(0, 0, mycanvas.width, mycanvas.height);
    var size ="";
   
       size = $('#from_' + index).find("#fontsizeadd").find("option:selected").text();
    
    var fontSize = "";
    //有没有放大
    var zoomsum = parseInt($("#zoomsum").text());
    if (zoomsum > 0) {
      zoomsum = zoomsum * 2;
      fontSize = parseInt(size.split("*")[0]) * zoomsum;
    } else {
      fontSize = parseInt(size.split("*")[0]);
    }
    var fontSizey = fontSize / 2;
    fontSizey = 0 - fontSizey;
    info = $("#from_" + index).find("#fosizeval").val();
    //  console.log("index:"+index);
    if (pd != 1) {

      new ZResize({
        stage: "#program", //舞台 
        item: '#program_' + index, //可缩放的类名 
      });
    }
    try {
      //电脑字体
      if ($("#from_" + index).find("#texttype").val() == "1") {
        //console.log("电脑字体:"+pd);
        //Canvasfont(pd);
       
          Canvasfont(pd);
       
      } else {
        drawText(context, info, 0, fontSizey, parseInt($("#program_" + index).outerWidth()), fontSize, $("#from_" + index).find("#fontcolor").val());
    
      }
    } catch (ex) {
      this.alert(ex);
    }
  }

}
//canvas对象  t文本数据  x默认0 y传文字的负高度    w宽度 fontsize字体大小 color文字颜色
window.drawText = function (context, t, x, y, w, fontsize, color) {
  var chr = t.split("");
  var temp = "";
  var row = [];
  context.font = fontsize + "px monospace";
  context.fillStyle = color;
  context.textBaseline = "middle";
  var c = 0;
  for (var a = 0; a < chr.length; a++) {
    var is = true;
    if (context.measureText(temp).width < w && context.measureText(temp + (chr[a])).width <= w) {
      //回车换行
      if (chr[a] == "\n") {
        is = false;
        row.push(temp); temp = "";
        chr[a] = "";
      } else {
        temp += chr[a];
      }
    }
    else if (is) {
      //回车换行
      if (chr[a] == "\n") {
        row.push(temp); temp = "";
        chr[a] = "";
      } else {
        row.push(temp);
        temp = chr[a];
      }
    }
  }
  row.push(temp);
  for (var b = 0; b < row.length; b++) {
    row[b] = row[b].replace(/\n/g, "");
    context.fillText(row[b], x, y + (b + 1) * fontsize);//字体计算换行
    // context.fillText(row[b], 40,100);//字体计算换行
  }
}

//电脑字体
var PROGRAM_FONT = { "1": "\u9ed1\u4f53", "2": "\u5b8b\u4f53", "3": "\u6977\u4f53", "4": "\u96b6\u4e66",}; // 广告字体\u5fae\u8f6f\u96c5\u9ed1
//var PROGRAM_FONT_CSS = { 1: 'SimHei', 2: 'SimSun', 3: 'KaiTi', 4: 'LiSu', 5: 'YaHei' };
var PROGRAM_FONT_CSS = { 1: 'SimHei', 2: 'SimSun', 3: 'KaiTi', 4: 'LiSu'};
var RGBCOLOR = { "255": "#ff0000", "65280": "#28ea28", "65535": "#ffff00", "16711680": "#2363f7", "16711935": "#d704ef", "16776960": "#0ef2f5", "16777215": "#ffffff" };
var fontSize = 32; var bordercolor = 0; var pageval = 1;
var parameter = [0.5, 2, 4, 100, 0];//参数
window.init = function () {
  var html = "";
  for (k in PROGRAM_FONT) { html += '<li><a val="' + k + '"><span style="font-family:' + PROGRAM_FONT_CSS[k] + '">' + PROGRAM_FONT[k] + '</span></a></li>'; } //字体options
  $("#from_" + selectid).find('.drop_font2').html(html);
  var iteminfo = { "font": 2 };
  updateTextArea($("#from_" + selectid).find("#text_pic_form"), iteminfo);
  $("#from_" + selectid).find(".drop_font2 li").click(function () {
    //console.log($(this).find("span").attr("style"));
    $("#from_" + selectid).find(".text-family").html("<span style=" + $(this).find("span").attr("style") + ">" + $(this).find("span").text() + "</span>");
  });
  //选择颜色
  $("#from_" + selectid).find(".drop_color2 li").click(function () {
    // alert(123);
    $("#from_" + selectid).find(".text-color").find("button:eq(0)").html("<span class=" + $(this).find("span").attr("class") + "></span>" + $(this).find("a").text());
  });
  //选择字号
  $("#from_" + selectid).find(".drop_fontsize2 li").click(function () {
    var fontsize=  $(this).find("a").attr("val");
    if (parseInt( $("#from_" + selectid).find("#width").val()) < parseFloat(fontsize)) {
      swal("OMG", "选择字体大小的不能超过分区宽度！", "error"); 
      return false;
    }
    if (parseInt($("#from_" + selectid).find("#high").val()) < parseFloat(fontsize)) {
      swal("OMG", "选择字体大小的不能超过分区高度！", "error");
      return false;
    }
    $("#from_" + selectid).find(".text-size").find("button:eq(0)").html($(this).find("a").text());
    $("#from_" + selectid).find(".text-size").find("button:eq(0)").attr("val", $(this).find("a").attr("val"));

    Canvasfont();
  });
  //输入
  $("#from_" + selectid).find('#editor').keyup(function () {
    //  if($(this).html()=="<br>"){$(this).html("");  return;};
    $("#from_" + selectid).find(".text-length").find('span').text("已输入" + $(this).html().replace(/&nbsp;/g, " ").replace(/<[^>]+>/g, "").length + "字");
    if ($(this).html().length == 0) { //清除所有文字时，重置属性
      $("#from_" + selectid).find("#editor").html("<font  color='#ff0000' face='SimSun'></font>");
      // return;//输入太快直接return掉，没进来了，一直按预览没删干净
    }
    Canvasfont();
  });
  //颜色
  $("#from_" + selectid).find(".drop_color2").on('mousedown', 'a', function () {
    $("#from_" + selectid).find(".text-family").find("button:eq(0)").html("<span class=" + $(this).find("span").attr("class") + "></span>" + $(this).text());
    document.execCommand("forecolor", false, RGBCOLOR[$(this).attr("val")]);
    Canvasfont();
  });
  //字体
  $("#from_" + selectid).find(".drop_font2").on('mousedown', 'a', function () {
    // $("#from_" + selectid).find(".text-color").find("button:eq(0)").html("<span class="+$(this).find("span").attr("class")+"></span>"+$(this).text()); 
    document.execCommand("fontName", false, PROGRAM_FONT_CSS[$(this).attr("val")]);
    Canvasfont();
  });
  //对齐
  $("#from_" + selectid).find(".alignment li").click(function () {
   $("#from_" + selectid).find(".alignmenttext").html("<span val='"+$(this).attr("val")+"'>"+$(this).find("span").text() + "</span>");
    Canvasfont();
  });
  //年格式选择
  $("#from_" + selectid).find(".dayselect li").click(function () {
    $("#from_" + selectid).find(".daytext").html("<span val='"+$(this).attr("val")+"'>"+$(this).find("span").text() + "</span>");

    var   timeval=writeCurrentDate(1,$("#from_" + selectid).find(".daytext span").text(),1);
    
    $("#from_" + selectid).find('#editor input[name=year]').attr("value",timeval);
    $("#from_" + selectid).find('#editor input[name=year]').val(timeval);
    Canvasfont();
   });
   //星期格式
   $("#from_" + selectid).find(".weekselect li").click(function () {
    $("#from_" + selectid).find(".weektext").html("<span val='"+$(this).attr("val")+"'>"+$(this).find("span").text() + "</span>");

    var   timeval=writeCurrentDate(2,$("#from_" + selectid).find(".weektext span").text(),1)
    $("#from_" + selectid).find('#editor input[name=day]').attr("value",timeval);

    $("#from_" + selectid).find('#editor input[name=day]').val(timeval)
    Canvasfont();
   });
   //时间格式
   $("#from_" + selectid).find(".hourselect li").click(function () {
    $("#from_" + selectid).find(".hourtext").html("<span val='"+$(this).attr("val")+"'>"+$(this).find("span").text() + "</span>");

    var timeval=writeCurrentDate(3,$("#from_" + selectid).find(".hourtext span").text(),1);
    timeval=timeval.replace("&nbsp;"," ");
     //alert(timeval);
     $("#from_" + selectid).find('#editor input[name=hour]').attr("value",timeval);
     $("#from_" + selectid).find('#editor input[name=hour]').val(timeval);
     Canvasfont();

   });

  //时间
  $("#from_" + selectid).find("#day").click(function () {
    $("#from_" + selectid).find('#editor').focus();
    if(typeof($("#from_" + selectid).find('#editor input[name=year]').val())=="undefined"){
    document.execCommand('insertHTML', false,writeCurrentDate(1,$("#from_" + selectid).find(".daytext span").text())); 
    }else{

      var   timeval=writeCurrentDate(1,$("#from_" + selectid).find(".daytext span").text(),1);
    
      $("#from_" + selectid).find('#editor input[name=year]').attr("value",timeval);

      $("#from_" + selectid).find('#editor input[name=year]').val(timeval)

    }
    Canvasfont();
   // $("#from_" + selectid).find('#editor input').addClass("day");
  
  });
  $("#from_" + selectid).find("#week").click(function () {    $("#from_" + selectid).find('#editor').focus();

    if(typeof($("#from_" + selectid).find('#editor input[name=day]').val())=="undefined"){
      document.execCommand('insertHTML', false,writeCurrentDate(2,$("#from_" + selectid).find(".weektext span").text())); 
    }else{
      var   timeval=writeCurrentDate(2,$("#from_" + selectid).find(".weektext span").text(),1)
      $("#from_" + selectid).find('#editor input[name=day]').attr("value",timeval);

      $("#from_" + selectid).find('#editor input[name=day]').val(timeval)
    }
   
    Canvasfont();
    $("#from_" + selectid).find('#editor input[name=day]').addClass("week");

  });
  $("#from_" + selectid).find("#hour").click(function () { 
    $("#from_" + selectid).find('#editor').focus();
if(typeof($("#from_" + selectid).find('#editor input[name=hour]').val())=="undefined"){

 // if($("#from_" + selectid).find(".hourtext span").text().indexOf("下/上午")==-1){
 // //  var timeval=writeCurrentDate(3,$("#from_" + selectid).find(".hourtext span").text(),1);


 // }else{

 //   document.execCommand('insertHTML', false,writeCurrentDate(3,$("#from_" + selectid).find(".hourtext span").text(),1));

 // }
var  writeval=writeCurrentDate(3,"HH时MM分SS秒")
 document.execCommand('insertHTML', false,writeval);


var timeval=writeCurrentDate(3,$("#from_" + selectid).find(".hourtext span").text(),1);
timeval=timeval.replace("&nbsp;"," ");



$("#from_" + selectid).find('#editor input[name=hour]').attr("value",timeval);
$("#from_" + selectid).find('#editor input[name=hour]').val(timeval);



}else{

var timeval=writeCurrentDate(3,$("#from_" + selectid).find(".hourtext span").text(),1);
timeval=timeval.replace("&nbsp;"," ");
//替换时间下午的空格
 //alert(timeval);
 $("#from_" + selectid).find('#editor input[name=hour]').attr("value",timeval);
 $("#from_" + selectid).find('#editor input[name=hour]').val(timeval);


}
Canvasfont(); 


 // $("#from_" + selectid).find('#editor input').addClass("hour");
});

  //计时格式
  $("#from_" + selectid).find(".timeNumSelect li").click(function () {
    $("#from_" + selectid).find('#editor').focus();
    $("#from_" + selectid).find(".timetext").html("<span val='"+$(this).attr("val")+"'>"+$(this).find("span").text() + "</span>");
   
    if (typeof ($("#from_" + selectid).find('#editor input[name=dowNum]').val()) == "undefined") {//(timeType,type,format,time)
      var timeval=writeCounDownDate(parseInt($("#from_" + selectid).find("#reckonType").val()), $("#from_" + selectid).find(".timetext span").attr("val"),$("#from_" + selectid).find(".timetext span").text(),$("#from_" + selectid).find("#targetTime").val())

   
      document.execCommand('insertHTML', false, timeval);
     
    }else{
      var time = $("#from_" + selectid).find("#targetTime").val();
   
      var startTime = new Date().getTime();
      //结束时间
      var endTime = new Date(time);
      endTime = endTime.getTime();
      if($("#from_" + selectid).find("#reckonType").val()!="0" &&endTime<=startTime){
        $("#from_" + selectid).find('#editor input[name=dowNum]').attr("value", "-时间超时-");
        $("#from_" + selectid).find('#editor input[name=dowNum]').val("-时间超时-");
      }else{
      var timeval=writeCounDownDate(parseInt($("#from_" + selectid).find("#reckonType").val()), $("#from_" + selectid).find(".timetext span").attr("val"),$("#from_" + selectid).find(".timetext span").text(),$("#from_" + selectid).find("#targetTime").val(),1)
      $("#from_" + selectid).find('#editor input[name=dowNum]').attr("value", timeval);
      $("#from_" + selectid).find('#editor input[name=dowNum]').val(timeval);
    }
  }

    Canvasfont();

  });
}
//替换html数据,过滤标签，（把标签替换成文字显示在画布上，画布不能识别标签）
window.tokenization = function (_playitem) {
  //对于IE,而chrome和firefox用<b>,对于IE和firefox换行用<br>newline,而chrome用<div>newline</div>
  console.log("tokenization"+ _playitem);
  var i = 0, tagpart = false, tag = "", txt_obj = [];
  var face = ["SimSun"];
  //  console.log(face);
  var color = ["#ff0000"];
  var fontsize = [fontSize];
  var value = _playitem.replace(/<br>/g, "\n").replace(/&nbsp;/g, " ");
   
  //当前为时间节目的时候
  if($("#from_" + selectid).find("#type").val()=="3"){
   

  value = value.replace(RegExp("<font color=\"#ff0000\" face=\"SimSun\"></font>", "g"), "");
 

  value = value.replace(RegExp("<input type=\"text\" name=\"day\" format=\""+$("#from_" + selectid).find("#editor input[name='day']").attr("format")+"\" readonly=\"\" value=\"", "g"), "").replace(RegExp("\" class=\"week\">", "g"), "");
  
 //年
  value = value.replace(RegExp("<input type=\"text\" format=\""+$("#from_" + selectid).find("#editor input[name='year']").attr("format")+"\" name=\"year\" readonly=\"\" value=\"", "g"), "");
 
// {/* <input type="text" name="hour" format="%H时%M分%S秒" readonly="" value="11时34分25秒"></input> */}

  value = value.replace(RegExp("<input type=\"text\" name=\"hour\" format=\""+$("#from_" + selectid).find("#editor input[name='hour']").attr("format")+"\" readonly=\"\" value=\"", "g"), "");
 
   value=value.replace(RegExp("\">", "g"), "");

  $("#from_" + selectid).find(".text-length").find('span').text("已输入" +  value.replace(/&nbsp;/g, " ").replace(/<[^>]+>/g, "").length + "字");

  }

  if($("#from_" + selectid).find("#type").val()=="5"){
    value = value.replace(RegExp("<font color=\"#ff0000\" face=\"SimSun\"></font>", "g"), "");
    value = value.replace(RegExp("<input type=\"text\" name=\"dowNum\" format=\""+$("#from_" + selectid).find("#editor input[name='dowNum']").attr("format")+"\" readonly=\"\" value=\"", "g"), "");
    value=value.replace(RegExp("\">", "g"), "");


    $("#from_" + selectid).find(".text-length").find('span').text("已输入" +  value.replace(/&nbsp;/g, " ").replace(/<[^>]+>/g, "").length + "字");
  
    }

  this.console.log("value:"+value);

  var str_len = value.length;
  for(i;i<str_len;i++){
    if(value[i]=="<"){
        tagpart= true;
        tag="";
    } else if(value[i]==">"){
        tagpart = false;
        if(txt_obj.length>0&&/^div$/.test(tag)){
           if (txt_obj[txt_obj.length - 1].length > 1) txt_obj.push(["\n"]);
          } else if(/^\/font$/.test(tag)) {
            face.pop();
            color.pop();
            fontsize.pop();
        } else{
            if(/face="([^\s]*)"/.test(tag)){
                face.push(RegExp.$1);
            } else{
                face.push(face[face.length-1]);
            }
            if(/color="([^\s]{1,7})"/.test(tag)){
                color.push(RegExp.$1);
            } else {
                color.push(color[color.length-1]);
            }
            if(/(\d*)px/.test(tag)){
                fontsize.push(RegExp.$1);
            } else {
                fontsize.push(fontsize[fontsize.length-1]);
            }
        }
    } else if(tagpart){
        tag+=value[i];
    } else {
      //时间分区
      if($("#from_" + selectid).find("#type").val()=="3"||$("#from_" + selectid).find("#type").val()=="5"){
      
            //全部字变颜色
         txt_obj.push([value[i],face[face.length-1],RGBCOLOR[$("#from_" + selectid).find(".drop_color2 li").eq($("#from_" + selectid).find("#fontcolor").get(0).selectedIndex).find("a").attr("val")],fontsize[fontsize.length-1],false]);
       }else{
         //单个字变颜色
         txt_obj.push([value[i],face[face.length-1],color[color.length-1],fontsize[fontsize.length-1],false]);
       
       }
    }
    
}
if(txt_obj.length > 0 && txt_obj[(txt_obj.length - 1)][0] == '\n') txt_obj.splice((txt_obj.length - 1) , 1);
return txt_obj;
}
var totalht = 0,totalwt=0;//总高宽度
var alignment="left";   //对齐方式

window.renderTextpic=function(ctx,type){

  alignment=$("#from_" + selectid).find(".alignmenttext span").attr("val");
  var text=tokenization($("#from_" + selectid).find("#editor").html());
  //this.console.log(text);
  //有没有放大
  var zoomsum=type==1?parseInt($("#zoomsum").text()):0;
  var width=0,height=0;
  if(type==1){
  width=parseInt($("#program_" + selectid).outerWidth());
  height=parseInt($("#program_" + selectid).outerHeight());
  }else{
     if(parseInt($("#zoomsum").text())>0){
      //  width=(parseInt($("#program_" + selectid).outerWidth())/((parseInt($("#zoomsum").text()) * parameter[1])));
      width=parseInt($("#program_" + selectid).outerWidth())/((parseInt($("#zoomsum").text()) * parameter[1]));

        height=(parseInt($("#program_" + selectid).outerHeight())/((parseInt($("#zoomsum").text()))));
      }
  }
  var textsize=parseInt($("#from_" + selectid).find(".text-size button:eq(0)").text());totalht=textsize;
  //this.alert(textsize);
  if (zoomsum > 0) {
    zoomsum = zoomsum * parameter[1];
    textsize=textsize*zoomsum;totalht=(textsize/parameter[1]);
  }
  //linewidth记录行宽度，textsizemax行框度 breadhtx=x定位text_obj存储数据,shops记录行号 ,alignw计算居中,verticalh计算垂直居中
  var textsizemax=width,linewidth=0,breadhtx=0,text_obj = [],shops=0,
  alignw=0,verticalh=0;  
  breadhty=parseInt($("#zoomsum").text())==0?parseInt($("#from_" + selectid).find(".text-size button:eq(0)").text())/2:parseInt($("#from_" + selectid).find(".text-size button:eq(0)").text())*parseInt($("#zoomsum").text());
  totalwt=0;
  $("#from_" + selectid).attr("totalwt",0);
  for (var i =0 ; i<text.length;i++){
    var chr = text[i][0].split("");
    for(var j=0;j<chr.length;j++){
      var regNumber = /\d+/, regString = /[a-zA-Z]+/,sinogram=true,
       pattern=new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~！@#￥……&*（）——|{}【】；：'。，、？-]");//验证0-9的任意数字最少出现1次，验证大小写26个字母任意字母最少出现1次。//||pattern.test(chr[j])
      if (regNumber.test(chr[j])||regString.test(chr[j])||pattern.test(chr[j])){
        sinogram=false;
        linewidth+=(textsize/parseInt(parameter[1]));//累计行宽度
        //文字
      }else{ 
        linewidth+=textsize;//累计行宽度
       
      }
      //换行
      //textsizemax+1
      if(intypeval.indexOf($("#from_" + selectid).find("#intype").val().toString())!=-1){
      if(parseInt(linewidth)>textsizemax||chr[j]=="\n"){
       // this.alert(linewidth);
        linewidth=0,alignw=0,verticalh=0;
        shops++;//累计行号
        //linewidth=chr[j]!="\n"?textsize:parameter[4];
        //y定位
          breadhty+=parseInt($("#zoomsum").text())==0?((textsize/2)*2)+parameter[2]:(textsize+parameter[2]);
        //最终图片高度
        totalht+=zoomsum>0?((textsize/parameter[1])+parameter[2]):(textsize+parameter[2]);
        linewidth=chr[j]=="\n"?0:sinogram?textsize:(textsize/parseInt(parameter[1]));
      }
    }else{
      //连续左右的情况下
      if(chr[j]!="\n"){
      totalwt=linewidth/2;
      }else{
        linewidth=linewidth-(sinogram?textsize:(textsize/parseInt(parameter[1])));
      }
      $("#from_" + selectid).attr("totalwt",totalwt);
   }
   // 则,16,SimSun,#ff0000,137,16,true,0,为,16,SimSun,#ff0000,153,16,true,0,全,16,SimSun,#ff0000,169,16,true,0,黑,16,SimSun,#ff0000,185,16,true,0,,,16,SimSun,#ff0000,202,16,false,0,最,16,SimSun,#ff0000,210,16,true,0,亮,16,SimSun,#ff0000,226,16,true,0,为,16,SimSun,#ff0000,242,16,true,0,全,16,SimSun,#ff0000,258,16,true,0
      //字符,字体大小,字体,颜色,x,y,?字符类型  行号  
      var breadhtx=sinogram==true?((linewidth-textsize)):(linewidth-(textsize/parameter[1]));
      if(chr[j]!="\n")
      
      text_obj.push([chr[j],textsize,text[i][1],text[i][2],(breadhtx==-1?0:breadhtx),breadhty,sinogram,shops]);
      //居中&&type==0
         // var intypeval=["1,4,5,8,9,12,13,16"];
      if(alignment=="center"&&chr[j]!="\n"){
      alignw+=sinogram==false?(textsize/parseInt(parameter[1])):textsize;
      //垂直居中开始值
       verticalh=shops==0?height/2:(height-((shops)*textsize))/2;
     
     //  alert(verticalh);
      //textsizemax/2:parseInt((textsizemax-val)/2);
      //居中
     var alignval=alignw==0?textsizemax/2:parseInt((textsizemax-alignw)/2);
     //垂直居中
    // var vertical=verticalh==0?height/2:parseInt((height-verticalh)/2);
    //遍历垂直居中对应位置
    //text_obj:1,16,SimSun,#ff0000,1,16,false,0,2,16,SimSun,#ff0000,1,36,false,1
    //alert(textsize);
    if(verticalh>0&&type==1){
      //this.alert(123);
     // this.alert(verticalh);
    //  console.log("verticalh:"+verticalh);
     for(var j=0;j<((shops)+1);j++){
      verticalh+=j==0?0:textsize;
      for(var ii=0;ii<text_obj.length;ii++){
      if(text_obj[ii][7]==j){
        text_obj[ii][5]=verticalh;
     }
    }}}
    //遍历居中对应位置
  //  redFruits.includes(fruit)
  // this.alert(intypeval.indexOf($("#from_" + selectid).find("#intype").val().toString()));
    if(intypeval.indexOf($("#from_" + selectid).find("#intype").val().toString())!=-1){
      var jj=0;   
      for(var ii=0;ii<text_obj.length;ii++){
        if(text_obj[ii][7]==shops){
         if(ii>0&&jj>0){
          alignval+=text_obj[ii-1][6]==false?((textsize/parseInt(parameter[1]))):textsize;
          text_obj[ii][4]=alignval;
         }else{
          text_obj[ii][4]=alignval;
         }
         jj++;
    }
  }
  }}}}
      //生成文字d,16,SimSun,#ff0000,1,16
      if(type==0)
       console.log("text_obj:"+text_obj);
      for(var i=0;i<text_obj.length;i++){
        ctx.font=text_obj[i][1]+"px "+text_obj[i][2];
        ctx.fillStyle = text_obj[i][3];
        //ctx.textAlign = "center";
        ctx.textBaseline = "middle";
        ctx.fillText(text_obj[i][0],text_obj[i][4],text_obj[i][5]);
        if(type==type&&text_obj[i][0]!="\n"){
          var _y=parseInt(text_obj[i][5])-(textsize/parameter[1]);
          var imgObj = {
            //'x': sinogram==true?(breadth-textsize):(breadth-(textsize/parameter[1])),
            'x':text_obj[i][4],
            'y':_y, 
            'w': ctx.measureText(text_obj[i][3]).width,
            'h':parseInt(textsize),
          }
         // console.log("measureText:"+ctx.measureText(text_obj[i][3]).width);
         setCtxImageData(ctx,imgObj,text_obj[i][3])
        }
      }
  };
//构建电脑字体
window.Canvasfont=function(pd){
 
  this.console.log("Canvasfontok:"+pd);
  var textcanvas = "<canvas id=textcanvas width=" + (parseInt($("#program_" + selectid).outerWidth())) + " height=" + $("#program_" + selectid).outerHeight() + " class=textcanvas></canvas>";
  if (pd != 1) {
    $("#program_" + selectid).html(textcanvas);
 
  }
  if (pd != 1) {
  new ZResize({
    stage: "#program", //舞台 
    item: '#program_' + selectid, //可缩放的类名 
  });
}
var mycanvas = $("#program_" + selectid).find("#textcanvas")[0];
var context = mycanvas.getContext("2d");
mycanvas.width =parseInt($("#program_" + selectid).outerWidth());
mycanvas.height =parseInt($("#program_" + selectid).outerHeight());
context.clearRect(0, 0, mycanvas.width, mycanvas.height);
renderTextpic(context,1);
setTimeout(function(){
  mycanvasadd();
},200);
// $("#from_" + selectid).find("#bmp").html(Canvas2Image.convertToImage(mycanvasadd, mycanvasadd.width, mycanvasadd.height, "bmp"));
//console.log("totalht:"+totalht);
// renderTextpic(context,parseFloat($("#from_" + selectid).find(".text-size button:eq(0)").attr("val"))*2,bordercolor,$("#from_" + selectid).find("#alignment").val());
}
window.updateTextArea = function (_formelem, _iteminfo) {
  if (_iteminfo["font"] != undefined) {
    $("#from_" + selectid).find(".text-family").html('<span style="font-family:' + PROGRAM_FONT_CSS[_iteminfo["font"]] + '">' + PROGRAM_FONT[_iteminfo["font"]] + '</span>');
  }
};

//生成图片
window.mycanvasadd=function(){
  try{
  if($("#from_" + selectid).find("#texttype").val()=="1"){
var mycanvasadd = $("#from_" + selectid).find("#mycanvasadd")[0];
//if(1==2){
//连续左移的情况下
totalwt=parseInt($("#from_" + selectid).attr("totalwt"));
if(totalwt>0){
 var w=parseInt(totalwt)/(parseInt($("#zoomsum").text())>0?(parseInt($("#program_" + selectid).outerWidth())/2):(parseInt($("#program_" + selectid).outerWidth())));
 
//w=parseInt(w)-(linewidthtow/2);
if(!Number.isInteger(w)){
  w=(parseInt($("#zoomsum").text())>0?(parseInt($("#program_" + selectid).outerWidth())/2):(parseInt($("#program_" + selectid).outerWidth())))*(parseInt(w)+1);
  totalwt=w;
}
 //1212121545454大幅度发4334放到放323232到213323232东方饭店323二位二翁无23232 
  console.log("totalwt:"+totalwt);
  mycanvasadd.width=parseInt(totalwt);
  mycanvasadd.height= (parseInt($("#zoomsum").text())>0?(parseInt($("#program_" + selectid).outerHeight())/2):(parseInt($("#program_" + selectid).outerHeight())))+parseInt($("#from_" + selectid).find(".text-size button:eq(0)").text());

  //console.log("breadhty:"+mycanvasadd.height);

}else{

  mycanvasadd.height=(totalht)+parameter[3];
  mycanvasadd.width = parseInt($("#zoomsum").text())>0?(parseInt($("#program_" + selectid).outerWidth())/2):(parseInt($("#program_" + selectid).outerWidth()));
}
var contextadd = mycanvasadd.getContext('2d');
mycanvasadd.width = mycanvasadd.width;
mycanvasadd.height = mycanvasadd.height;
contextadd.clearRect(0, 0, mycanvasadd.width, mycanvasadd.height);
contextadd.fillStyle="#000000";
contextadd.fillRect(0,0,mycanvasadd.width, mycanvasadd.height);
renderTextpic(contextadd, parseInt($("#zoomsum").text())>0?0:1);
var base64 = mycanvasadd.toDataURL('image/png',1);
console.log(base64);
$("#from_" + selectid).find("#imgDataURL").val(base64);
}
}catch(ex){

}
}

//处理暗点,提亮色彩
window.setCtxImageData = function(ctx_tmp,imgObj,color){
  if(imgObj.w == 0) return;
  var colorArr = {'#ff0000':'255','#00ff00':'65280','#28ea28':'65280','#ffff00':'65535','#0000ff':'16711680','#ff00ff':'16711935','#00ffff':'16776960','#ffffff':'16777215','#d704ef':'16711935','#2363f7':'16711680','#0ef2f5':'16776960'}
  var _c = colorArr[color.toLowerCase()];		
  //this.console.log("_c:"+color);			
  var imgData = ctx_tmp.getImageData(imgObj.x,imgObj.y,imgObj.w,imgObj.h);
  var r = _c & 0xFF, g = (_c >> 8) & 0xFF, b = (_c >> 16) & 0xFF;
  
  var filter = 0x3F;	
  for(var k=0;k<imgData.data.length;k+=4){
    if(imgData.data[k+0] > filter | imgData.data[k+1] > filter | imgData.data[k+2] > filter){
      imgData.data[k+0]=r;
      imgData.data[k+1]=g;
      imgData.data[k+2]=b;
      //this.alert(r);  this.alert(g); this.alert(b);
      if(imgData.data[k+3] > filter){
        imgData.data[k+3]=255;
      }else{
        imgData.data[k+3]=0;	
      }
    }else{
      imgData.data[k+0]=0;
      imgData.data[k+1]=0;
      imgData.data[k+2]=0;
      imgData.data[k+3]=0;
    }
  }
  //console.log(imgData);
ctx_tmp.putImageData(imgData,imgObj.x,imgObj.y);	
}


//时间,val第一次赋空标签，1是第二次填值
window.writeCurrentDate=function(type,format,val) {
  //formatval:%Y的值;format:当前时间替换成%Y;formatback:%Y替换成当前时间
  let  formatval=format;  
  let formatback=format; 
  let formatadd=format;
  var now = new Date();
  var year = now.getFullYear(); //得到年份
  var month = now.getMonth();//得到月份
  var date = now.getDate();//得到日期
  var day = now.getDay();//得到周几
  var hour = now.getHours();//得到小时
  var minu = now.getMinutes();//得到分钟
  var sec = now.getSeconds();//得到秒
　var MS = now.getMilliseconds();//获取毫秒
  var week;
  month = month + 1;
  if (month < 10){ month = "0" + month;}
  if (date < 10) {date = "0" + date;}
  if (hour < 10) {hour = "0" + hour;}
  if (minu < 10) {minu = "0" + minu;}
  if (sec < 10) {sec = "0" + sec;}
  if (MS < 100){MS = "0" + MS;}
  var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
  week = arr_week[day];
  var time = "";
  var timeval="";
  if(type==1){
    
    
    format=format.replace("YYYY",year);
    format=format.replace("MM",month);
    format=format.replace("DD",date);
    var YY=year.toString().substring(year.length-2,2);
    format=format.replace("YY", YY);

    formatback=formatback.replace("%Y",year);
    formatback=formatback.replace("%m",month);
    formatback=formatback.replace("%d",date);
    formatback=formatback.replace("%y",YY);


    // time = "<input type='text' style='width:60px' name='year' readonly value="+year+ ">年" + "<input type='text' name='month' readonly value="+month+ ">月" + "<input type='text' name='date' readonly value="+date+ ">日";
    //格式判断
    formatval=formatval.replace("YYYY","%Y");
    formatval=formatval.replace("MM","%m");
    formatval=formatval.replace("DD","%d");
    formatval=formatval.replace("YY", "%y");
      time = "<input type='text' style='' format="+formatval+" name='year' readonly value="+format+">";
      timeval=format;
    //  alert(timeval)
      $("#from_" + selectid).find('#editor input[name=year]').attr("format",formatval);
  }
  if(type==2){
  var weekend=week.charAt(week.length-1);
  week=week.substring(0,week.length-1);
  format=format.replace("一",weekend);
  // format=format.replace("1",day=day==0?7:day);

  formatval=formatval.replace("一","%w");
  // formatval=formatval.replace("1","%w");
  
  formatback=formatback.replace("%w",weekend);
  // formatback=formatback.replace("%w");
  
  time="<input type='text' name='day' format="+formatval+" readonly  value="+format+">";
  timeval=format;


  
  $("#from_" + selectid).find('#editor input[name=day]').attr("format",formatval);
  }
  if(type==3){
    //HH时MM分SS秒
    format=format.replace("MM",minu);
    format=format.replace("SS",sec);

    formatval=formatval.replace("MM","%M");
    formatval=formatval.replace("SS","%S");


    formatback=formatback.replace("%M",minu);
    formatback=formatback.replace("%S",sec);

    //12小时制
    var ampmtext = hour >= 12 ? '下午' : '上午';
   
   

    if(formatback.indexOf("%I")!=-1){
      formatback=formatback.replace("%I",hour);
      formatback=formatback.replace(" %p","&nbsp;"+ampmtext);
      
    }else{
      
    if(format.indexOf("下/上午")==-1){
    format=format.replace("HH",hour);
    formatval=formatval.replace("HH","%H");
    
    formatback=formatback.replace("%H",hour);
    
    }else{
      hour = hour % 12;
      hour = hour ? hour : 12; // the hour '0' should be '12'
     // var ampm = hour >= 12 ? 'PM' : 'AM';
      format=format.replace("HH",hour);
     // format=format.replace(" A/PM"," "+ampm);
     format=format.replace(" 下/上午","&nbsp;"+ampmtext);
      
    //  formatval=formatval.replace(" A/PM"," %P");
      formatval=formatval.replace("HH","%I");
      formatval=formatval.replace(" 下/上午"," %p");
      

    }
     // format=format.replace(" %P","&nbsp;"+ampmtext,");
    }
    
   

    
    // time="<input type='text' name='hour' readonly  value="+hour+ ">"+"时"+"<input type='text' name='minu' readonly  value="+minu+ ">"+"分"+"<input type='text' name='sec' readonly  value="+sec+ ">"+"秒";
   // time="<input type='text' name='hour' readonly  value="+hour+"时"+minu+"分"+sec+"秒>";
   // time = hour + "时" + minu + "分" + sec + "秒";
   time="<input type='text' name='hour' format="+formatval+" readonly  value="+format+">";

   $("#from_" + selectid).find('#editor input[name=hour]').attr("format",formatval);
   timeval=format; 

  
  }
  
  if(val==1)
  time=format;
 // alert("time:"+time)
  if(val==2)
  time=formatback.replace("&nbsp;"," ");
  //当前日期赋值给当前日期输入框中（jQuery easyUI）
 // $("#currentDate").html(time);
  //设置得到当前日期的函数的执行间隔时间，每1000毫秒刷新一次。
  //var timer = setTimeout("writeCurrentDate()", 1000);
  if(val==3)
  time=formatadd;
  return time;
}
//时间
//timetype:计时类型,type:计时格式类型,format:计时格式,time:基准时间
window.writeCounDownDate = function (timeType, type, format, time,val) {


  let formatval = format;
  //开始时间
  var now = new Date();
  var startTime = now.getTime();
  //结束时间
  var endTime = new Date(time);
  endTime = endTime.getTime();

  var diffTime =Math.floor((endTime - startTime) / 1000);//差值

  let count = 0;
  //计算


  var days = 0; //计算剩余的天数 
  var hours = 0; //计算剩余的小时 
  var minutes = 0;//计算剩余的分钟 
  var seconds = 0;//计算剩余的秒数 

  var time = ""; //标签



  if (type == 1) {
    seconds = timeType == 0 ? 0 : parseInt(diffTime);
    format = format.replace("SS", seconds);
  }
  if (type == 8) {
    days = timeType == 0 ? 0 : parseInt(diffTime / 60 / 60 / 24); //计算剩余的天数 

    format = format.replace("DD", days);

  }

  if (type == 15) {
    days = timeType == 0 ? 0 : Math.floor(diffTime / (24 * 60 * 60)); //计算剩余的天数 
    hours = timeType == 0 ? 0 : Math.floor(diffTime / (60 * 60) % 24); //计算剩余的小时 
    minutes = timeType == 0 ? 0 : Math.floor(diffTime / (60 * 60) % 24);//计算剩余的分钟 
    seconds = timeType == 0 ? 0 : Math.floor(diffTime % 60);//计算剩余的秒数 
    format = format.replace("DD", days);
    format = format.replace("HH", hours);
    format = format.replace("MM", minutes);
    format = format.replace("SS", seconds);
  
  }
  //   time="<input type='text' name='day' format="+formatval+" readonly  value="+format+">";
  
  time = "<input type='text' name='dowNum' format='" + formatval + "' readonly value=" + format + ">";
  


  $("#from_" + selectid).find('#editor input[name=dowNum]').attr("format", formatval);

  if (val == 1)
    time = format;


  return time;
}

